2022-11-03 08:15:17 -07:00
|
|
|
#include <iostream>
|
|
|
|
#include <utility>
|
|
|
|
|
2022-11-04 09:38:01 -07:00
|
|
|
#include <intcode/intcode.hpp>
|
2022-11-03 08:15:17 -07:00
|
|
|
|
2022-11-03 12:53:10 -07:00
|
|
|
using namespace intcode;
|
|
|
|
|
2022-11-03 08:15:17 -07:00
|
|
|
namespace {
|
|
|
|
|
2022-11-03 14:43:47 -07:00
|
|
|
auto Compute(Machine machine, ValueType x, ValueType y) {
|
|
|
|
machine.At(1) = x;
|
|
|
|
machine.At(2) = y;
|
2022-11-04 08:29:02 -07:00
|
|
|
Step(machine);
|
2022-11-03 14:43:47 -07:00
|
|
|
return machine.At(0);
|
2022-11-03 08:15:17 -07:00
|
|
|
}
|
|
|
|
|
2022-11-03 12:53:10 -07:00
|
|
|
} // namespace
|
2022-11-03 08:15:17 -07:00
|
|
|
|
|
|
|
auto main() -> int {
|
2022-11-03 14:43:47 -07:00
|
|
|
auto machine = Machine{ParseStream(std::cin)};
|
2022-11-03 08:15:17 -07:00
|
|
|
|
2022-11-03 14:43:47 -07:00
|
|
|
std::cout << "Part 1: " << Compute(machine, 12, 2) << std::endl;
|
2022-11-03 08:15:17 -07:00
|
|
|
|
2022-11-03 12:53:10 -07:00
|
|
|
for (std::int64_t i = 0; i < 100; i++) {
|
|
|
|
for (std::int64_t j = 0; j < 100; j++) {
|
2022-11-03 14:43:47 -07:00
|
|
|
if (19690720 == Compute(machine, i, j)) {
|
2022-11-03 12:53:10 -07:00
|
|
|
std::cout << "Part 2: " << 100 * i + j << std::endl;
|
|
|
|
}
|
2022-11-03 08:15:17 -07:00
|
|
|
}
|
2022-11-03 12:53:10 -07:00
|
|
|
}
|
|
|
|
}
|