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