23 lines
711 B
C++
23 lines
711 B
C++
#include <iostream>
|
|
#include <utility>
|
|
|
|
#include <intcode.hpp>
|
|
|
|
namespace {
|
|
auto compute(intcode machine, std::int64_t d) -> std::int64_t {
|
|
std::int64_t 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;
|
|
}
|
|
}
|
|
|
|
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), 5) << std::endl;
|
|
} |