32 lines
698 B
C++
32 lines
698 B
C++
#include <iostream>
|
|
#include <utility>
|
|
|
|
#include <intcode/intcode.hpp>
|
|
using namespace intcode;
|
|
|
|
namespace {
|
|
|
|
auto Compute(Machine machine, ValueType d) -> ValueType {
|
|
ValueType 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;
|
|
}},
|
|
Step(machine)));
|
|
return last_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), 5) << std::endl;
|
|
}
|