aocpp/day09.cpp
2022-11-03 08:15:17 -07:00

25 lines
694 B
C++

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