46 lines
948 B
C++
46 lines
948 B
C++
#include <iostream>
|
|
#include <utility>
|
|
#include <tuple>
|
|
#include <map>
|
|
|
|
#include <aocpp/Startup.hpp>
|
|
#include <aocpp/Coord.hpp>
|
|
#include <intcode/intcode.hpp>
|
|
using namespace aocpp;
|
|
using namespace intcode;
|
|
|
|
namespace {
|
|
|
|
auto Compute(Machine machine, ValueType start)
|
|
-> std::map<Coord, ValueType> {
|
|
|
|
Coord here {0,0};
|
|
std::map<Coord, ValueType> paint {{here,start}};
|
|
Coord dir {0, -1};
|
|
|
|
bool next_color = true;
|
|
|
|
Run(machine,
|
|
[&]() { return paint[here]; },
|
|
[&](auto o) {
|
|
if (next_color) {
|
|
paint[here] = o;
|
|
} else {
|
|
dir = (o ? CW : CCW)(dir);
|
|
here += dir;
|
|
}
|
|
next_color = !next_color;
|
|
});
|
|
|
|
return paint;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
auto main(int argc, char** argv) -> int {
|
|
auto fin = aocpp::Startup(argc, argv);
|
|
auto machine = Machine{ParseStream(fin)};
|
|
std::cout << "Part 1: " << Compute(machine, 0).size() << "\nPart 2\n";
|
|
Draw(std::cout, Compute(std::move(machine), 1));
|
|
}
|