aocpp/day09.cpp
2022-11-03 12:53:10 -07:00

32 lines
666 B
C++

#include <iostream>
#include <utility>
#include <intcode.hpp>
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;
}