46 lines
911 B
C++
46 lines
911 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(std::istream & in, std::ostream & out) -> void
|
|
{
|
|
auto machine = Machine{ParseStream(in)};
|
|
out << "Part 1: " << Compute(machine, 0).size() << "\nPart 2\n";
|
|
Draw(out, Compute(std::move(machine), 1));
|
|
}
|