57 lines
1.1 KiB
C++
57 lines
1.1 KiB
C++
|
#include <iostream>
|
||
|
#include <utility>
|
||
|
#include <tuple>
|
||
|
#include <map>
|
||
|
|
||
|
#include <intcode.hpp>
|
||
|
using namespace intcode;
|
||
|
|
||
|
namespace {
|
||
|
|
||
|
using Coord = std::pair<ValueType, ValueType>;
|
||
|
|
||
|
auto Compute(Machine machine, ValueType start)
|
||
|
-> std::map<Coord, ValueType> {
|
||
|
|
||
|
Coord here {0,0};
|
||
|
std::map<Coord, ValueType> paint {{here,start}};
|
||
|
ValueType dx = 1;
|
||
|
ValueType dy = 0;
|
||
|
|
||
|
for (;;) {
|
||
|
auto effect = machine.Step();
|
||
|
|
||
|
if (std::holds_alternative<Halt>(effect)) {
|
||
|
return paint;
|
||
|
}
|
||
|
|
||
|
std::get<Input>(effect).pos = paint[here];
|
||
|
auto color = std::get<Output>(machine.Step()).val;
|
||
|
auto dir = std::get<Output>(machine.Step()).val;
|
||
|
paint[here] = color;
|
||
|
|
||
|
std::swap(dx, dy);
|
||
|
if (dir) {
|
||
|
dx = -dx;
|
||
|
} else {
|
||
|
dy = -dy;
|
||
|
}
|
||
|
here.first += dx;
|
||
|
here.second += dy;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
auto Draw(std::map<Coord, ValueType> image) {
|
||
|
ValueType minX = 1000, maxX = -1000, minY = 1000, maxY = -1000;
|
||
|
}
|
||
|
|
||
|
} // namespace
|
||
|
|
||
|
auto main() -> int {
|
||
|
auto machine = Machine{ParseStream(std::cin)};
|
||
|
|
||
|
std::cout << "Part 1: " << Compute(machine, 0).size() << std::endl;
|
||
|
|
||
|
Draw(Compute(std::move(machine), 1));
|
||
|
}
|