aocpp/day09.cpp
2022-11-04 08:29:02 -07:00

32 lines
661 B
C++

#include <iostream>
#include <utility>
#include <intcode.hpp>
using namespace intcode;
namespace {
auto Compute(Machine machine, ValueType d) -> ValueType {
ValueType 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;
}},
Step(machine)));
return output;
}
} // namespace
auto main() -> int {
auto machine = Machine{ParseStream(std::cin)};
std::cout << "Part 1: " << Compute(machine, 1) << std::endl;
std::cout << "Part 2: " << Compute(std::move(machine), 2) << std::endl;
}