32 lines
695 B
C++
32 lines
695 B
C++
#include <iostream>
|
|
#include <utility>
|
|
|
|
#include <intcode.hpp>
|
|
using namespace intcode;
|
|
|
|
namespace {
|
|
|
|
auto compute(Machine machine, value_type d) -> value_type {
|
|
value_type last_output = -1;
|
|
while (std::visit(overloaded{
|
|
[](Halt) { return false; },
|
|
[d, &machine](Input arg) {
|
|
arg.pos = d;
|
|
return true;
|
|
},
|
|
[&last_output](Output arg) {
|
|
last_output = arg.val;
|
|
return true;
|
|
}},
|
|
machine.step()));
|
|
return last_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), 5) << std::endl;
|
|
}
|