aocpp/2019/11.cpp
2023-01-31 08:59:09 -08:00

46 lines
903 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) -> void
{
auto machine = Machine{ParseStream(in)};
std::cout << "Part 1: " << Compute(machine, 0).size() << "\nPart 2\n";
Draw(std::cout, Compute(std::move(machine), 1));
}