aocpp/2019/09.cpp
2023-01-31 09:15:25 -08:00

38 lines
938 B
C++

#include <iostream>
#include <utility>
#include <doctest.h>
#include <aocpp/Startup.hpp>
#include <intcode/intcode.hpp>
using namespace intcode;
namespace {
auto Compute(Machine machine, ValueType d) -> ValueType {
ValueType output = -1;
Run(machine,
[=](){ return d; },
[&](auto o) { output = o; });
return output;
}
} // namespace
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);
}
}
auto Main(std::istream & in, std::ostream & out) -> void
{
auto machine = Machine{ParseStream(in)};
out << "Part 1: " << Compute(machine, 1) << std::endl;
out << "Part 2: " << Compute(std::move(machine), 2) << std::endl;
}