#include #include #include using namespace intcode; namespace { auto compute(Machine machine, value_type d) -> value_type { value_type output = -1; while (std::visit(overloaded{ [](Halt) { return false; }, [d](Input arg) { arg.pos = d; return true; }, [&output](Output arg) { output = arg.val; return false; }}, machine.step())); return output; } } // namespace auto main() -> int { auto machine = Machine{parse_stream(std::cin)}; std::cout << "Part 1: " << compute(machine, 1) << std::endl; std::cout << "Part 2: " << compute(std::move(machine), 2) << std::endl; }