2022-11-03 08:15:17 -07:00
|
|
|
#include <iostream>
|
|
|
|
#include <utility>
|
|
|
|
|
2022-11-06 21:12:30 -08:00
|
|
|
#include <aocpp/Startup.hpp>
|
2022-11-04 09:38:01 -07:00
|
|
|
#include <intcode/intcode.hpp>
|
2022-11-03 12:53:10 -07:00
|
|
|
using namespace intcode;
|
2022-11-03 08:15:17 -07:00
|
|
|
|
|
|
|
namespace {
|
2022-11-03 12:53:10 -07:00
|
|
|
|
2022-11-03 14:43:47 -07:00
|
|
|
auto Compute(Machine machine, ValueType d) -> ValueType {
|
|
|
|
ValueType last_output = -1;
|
2022-11-04 11:36:30 -07:00
|
|
|
Run(machine,
|
|
|
|
[=]() { return d; },
|
|
|
|
[&](auto o) { last_output = o; });
|
2022-11-03 12:53:10 -07:00
|
|
|
return last_output;
|
2022-11-03 08:15:17 -07:00
|
|
|
}
|
|
|
|
|
2022-11-03 12:53:10 -07:00
|
|
|
} // namespace
|
|
|
|
|
2022-11-06 11:33:20 -08:00
|
|
|
auto main(int argc, char** argv) -> int {
|
2022-11-07 21:00:14 -08:00
|
|
|
auto machine = Machine{ParseStream(aocpp::Startup(argc, argv))};
|
2022-11-03 14:43:47 -07:00
|
|
|
std::cout << "Part 1: " << Compute(machine, 1) << std::endl;
|
|
|
|
std::cout << "Part 2: " << Compute(std::move(machine), 5) << std::endl;
|
2022-11-03 12:53:10 -07:00
|
|
|
}
|