2022-11-03 19:49:07 -07:00
|
|
|
#include <iostream>
|
|
|
|
#include <utility>
|
|
|
|
#include <tuple>
|
|
|
|
#include <map>
|
|
|
|
|
2022-11-06 21:12:30 -08:00
|
|
|
#include <aocpp/Startup.hpp>
|
|
|
|
#include <aocpp/Coord.hpp>
|
2022-11-04 09:38:01 -07:00
|
|
|
#include <intcode/intcode.hpp>
|
2022-11-06 21:12:30 -08:00
|
|
|
using namespace aocpp;
|
2022-11-03 19:49:07 -07:00
|
|
|
using namespace intcode;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
auto Compute(Machine machine, ValueType start)
|
|
|
|
-> std::map<Coord, ValueType> {
|
2022-11-04 11:37:32 -07:00
|
|
|
|
2022-11-03 19:49:07 -07:00
|
|
|
Coord here {0,0};
|
|
|
|
std::map<Coord, ValueType> paint {{here,start}};
|
2022-11-04 17:39:35 -07:00
|
|
|
Coord dir {0, -1};
|
2022-11-03 19:49:07 -07:00
|
|
|
|
2022-11-04 11:36:30 -07:00
|
|
|
bool next_color = true;
|
|
|
|
|
|
|
|
Run(machine,
|
|
|
|
[&]() { return paint[here]; },
|
|
|
|
[&](auto o) {
|
|
|
|
if (next_color) {
|
|
|
|
paint[here] = o;
|
|
|
|
} else {
|
2022-11-04 17:39:35 -07:00
|
|
|
dir = (o ? CW : CCW)(dir);
|
2022-11-04 21:27:08 -07:00
|
|
|
here += dir;
|
2022-11-04 11:36:30 -07:00
|
|
|
}
|
|
|
|
next_color = !next_color;
|
|
|
|
});
|
|
|
|
|
|
|
|
return paint;
|
2022-11-03 19:49:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2022-11-06 11:33:20 -08:00
|
|
|
auto main(int argc, char** argv) -> int {
|
2022-11-07 21:00:14 -08:00
|
|
|
auto machine = Machine{ParseStream(aocpp::Startup(argc, argv))};
|
2022-11-03 20:16:11 -07:00
|
|
|
std::cout << "Part 1: " << Compute(machine, 0).size() << "\nPart 2\n";
|
|
|
|
Draw(std::cout, Compute(std::move(machine), 1));
|
2022-11-03 19:49:07 -07:00
|
|
|
}
|