#include #include #include #include #include #include using namespace intcode; namespace { auto Compute1(Machine machine) -> std::size_t { std::set screen; for (;;) { auto effect = Step(machine); if (std::holds_alternative(effect)) { return screen.size(); } auto x = std::get(effect).val; auto y = std::get(Step(machine)).val; auto v = std::get(Step(machine)).val; if (2 == v) { screen.insert({x,y}); } else { screen.erase({x,y}); } } } auto Compute2(Machine machine) { ValueType score {0}; ValueType paddleX {0}; ValueType ballX {0}; machine.At(0) = 2; for(;;) { auto effect = Step(machine); if (std::holds_alternative(effect)) { return score; } else if (auto i = std::get_if(&effect)) { i->pos = paddleX < ballX ? 1 : paddleX > ballX ? -1 : 0; } else { auto x = std::get(effect).val; auto y = std::get(Step(machine)).val; auto v = std::get(Step(machine)).val; if (-1 == x && 0 == y) { score = v; } else { switch (v) { case 3: // paddle paddleX = x; break; case 4: // ball ballX = x; break; } } } } } } // namespace auto main() -> int { auto machine = Machine{ParseStream(std::cin)}; std::cout << "Part 1: " << Compute1(machine) << std::endl; std::cout << "Part 2: " << Compute2(std::move(machine)) << std::endl; }