2022-11-03 08:15:17 -07:00
|
|
|
#include <iostream>
|
|
|
|
#include <utility>
|
|
|
|
|
2022-11-15 18:20:41 -08:00
|
|
|
#include <doctest.h>
|
|
|
|
|
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 14:43:47 -07:00
|
|
|
auto Compute(Machine machine, ValueType d) -> ValueType {
|
|
|
|
ValueType output = -1;
|
2022-11-04 11:36:30 -07:00
|
|
|
Run(machine,
|
|
|
|
[=](){ return d; },
|
|
|
|
[&](auto o) { output = o; });
|
2022-11-03 12:53:10 -07:00
|
|
|
return output;
|
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
|
|
|
|
2022-11-15 18:20:41 -08:00
|
|
|
TEST_SUITE("documented examples") {
|
|
|
|
TEST_CASE("part 1") {
|
|
|
|
std::vector<ValueType> pgm {109,1,204,-1,1001,100,1,100,1008,100,16,101,1006,101,0,99};
|
|
|
|
std::vector<ValueType> output;
|
|
|
|
Machine machine {pgm};
|
|
|
|
Run(machine, []() -> ValueType{ REQUIRE(false); return 0; }, [&](ValueType o){ output.push_back(o);});
|
|
|
|
REQUIRE(pgm == output);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-31 09:15:15 -08:00
|
|
|
auto Main(std::istream & in, std::ostream & out) -> void
|
2023-01-31 08:58:42 -08:00
|
|
|
{
|
|
|
|
auto machine = Machine{ParseStream(in)};
|
2023-01-31 09:15:15 -08:00
|
|
|
out << "Part 1: " << Compute(machine, 1) << std::endl;
|
|
|
|
out << "Part 2: " << Compute(std::move(machine), 2) << std::endl;
|
2022-11-03 12:53:10 -07:00
|
|
|
}
|