make output stream a Main parameter

This commit is contained in:
Eric Mertens 2023-01-31 09:15:15 -08:00
parent c6264a2a1b
commit 2f7949b8da
62 changed files with 191 additions and 190 deletions

View File

@ -46,10 +46,10 @@ TEST_SUITE("2017-01 examples") {
}
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
std::string input;
std::getline(in, input);
std::cout << "Part 1: " << Part1(input) << std::endl;
std::cout << "Part 2: " << Part2(input) << std::endl;
out << "Part 1: " << Part1(input) << std::endl;
out << "Part 2: " << Part2(input) << std::endl;
}

View File

@ -66,9 +66,9 @@ TEST_SUITE("2017-02 examples") {
}
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto const [p1,p2] = Omnibus(in);
std::cout << "Part 1: " << p1 << std::endl;
std::cout << "Part 2: " << p2 << std::endl;
out << "Part 1: " << p1 << std::endl;
out << "Part 2: " << p2 << std::endl;
}

View File

@ -57,9 +57,9 @@ TEST_SUITE("2017-05 examples") {
}
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto input {Parse(in)};
std::cout << "Part 1: " << Run1(input) << std::endl;
std::cout << "Part 2: " << Run2(std::move(input)) << std::endl;
out << "Part 1: " << Run1(input) << std::endl;
out << "Part 2: " << Run2(std::move(input)) << std::endl;
}

View File

@ -80,10 +80,10 @@ TEST_SUITE("2017-06 examples") {
}
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto input {Parse(in)};
auto const answer = CycleSearch(input);
std::cout << "Part 1: " << answer.first << std::endl;
std::cout << "Part 2: " << answer.second << std::endl;
out << "Part 1: " << answer.first << std::endl;
out << "Part 2: " << answer.second << std::endl;
}

View File

@ -9,7 +9,7 @@
#include <aocpp/Parsing.hpp>
#include <knothash.hpp>
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
std::string line;
std::getline(in, line);
@ -20,7 +20,7 @@ auto Main(std::istream & in) -> void
}
auto result = knothash::hash_ex<256>(1, lengths1.begin(), lengths1.end());
std::cout << "Part 1: " << long{result[0]} * long{result[1]} << std::endl;
out << "Part 1: " << long{result[0]} * long{result[1]} << std::endl;
std::cout << "Part 2: " << knothash::render(knothash::hash(line)) << std::endl;
out << "Part 2: " << knothash::render(knothash::hash(line)) << std::endl;
}

View File

@ -60,11 +60,11 @@ TEST_SUITE("2017-11 examples") {
}
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
std::string line;
std::getline(in, line);
auto const [part1, part2] = Walk(line);
std::cout << "Part 1: " << part1 << std::endl;
std::cout << "Part 2: " << part2 << std::endl;
out << "Part 1: " << part1 << std::endl;
out << "Part 2: " << part2 << std::endl;
}

View File

@ -101,10 +101,10 @@ TEST_SUITE("2017-12 examples") {
}
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto const input {Parse(in)};
auto const [part1, part2] = LinkNodes(input);
std::cout << "Part 1: " << part1 << std::endl;
std::cout << "Part 2: " << part2 << std::endl;
out << "Part 1: " << part1 << std::endl;
out << "Part 2: " << part2 << std::endl;
}

View File

@ -72,9 +72,9 @@ TEST_SUITE("2017-12 examples") {
}
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto input {Parse(in)};
std::cout << "Part 1: " << Caught(input) << std::endl;
std::cout << "Part 2: " << Delay(std::move(input)) << std::endl;
out << "Part 1: " << Caught(input) << std::endl;
out << "Part 2: " << Delay(std::move(input)) << std::endl;
}

View File

@ -94,11 +94,11 @@ TEST_CASE("flqrgnkx") {
}
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
std::string input;
std::getline(in, input);
auto const rows {MakeRows(std::move(input))};
std::cout << "Part 1: " << CountBits(rows) << std::endl;
std::cout << "Part 2: " << CountComponents(rows) << std::endl;
out << "Part 1: " << CountBits(rows) << std::endl;
out << "Part 2: " << CountComponents(rows) << std::endl;
}

View File

@ -59,10 +59,10 @@ TEST_SUITE("2017-17 examples") {
}
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
int steps;
in >> steps;
std::cout << "Part 1: " << Part1(steps, 2017) << std::endl;
std::cout << "Part 2: " << Part2(steps, 50'000'000) << std::endl;
out << "Part 1: " << Part1(steps, 2017) << std::endl;
out << "Part 2: " << Part2(steps, 50'000'000) << std::endl;
}

View File

@ -237,9 +237,9 @@ TEST_SUITE("documented examples") {
}
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto const program {Parse(in)};
std::cout << "Part 1: " << Part1(program) << std::endl;
std::cout << "Part 2: " << Part2(program) << std::endl;
out << "Part 1: " << Part1(program) << std::endl;
out << "Part 2: " << Part2(program) << std::endl;
}

View File

@ -71,9 +71,9 @@ TEST_SUITE("2017-19 examples") {
}
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto const [part1, part2] = Drive(Grid::Parse(in));
std::cout << "Part 1: " << part1 << std::endl;
std::cout << "Part 2: " << part2 << std::endl;
out << "Part 1: " << part1 << std::endl;
out << "Part 2: " << part2 << std::endl;
}

View File

@ -476,11 +476,11 @@ TEST_SUITE("2018-15 examples") {
}
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto const grid {Grid::Parse(in)};
Game game {std::move(grid)};
//game.debug_out_ = &std::cout;
std::cout << "Part 1: " << *Game{game}.Simulate() << std::endl;
std::cout << "Part 2: " << Part2(std::move(game)).first << std::endl;
//game.debug_out_ = &out;
out << "Part 1: " << *Game{game}.Simulate() << std::endl;
out << "Part 2: " << Part2(std::move(game)).first << std::endl;
}

View File

@ -44,7 +44,7 @@ TEST_CASE("part 2") {
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
std::int64_t weight;
std::int64_t part1 = 0;
@ -55,6 +55,6 @@ auto Main(std::istream & in) -> void
part2 += fuel2(weight);
}
std::cout << "Part 1: " << part1 << std::endl;
std::cout << "Part 2: " << part2 << std::endl;
out << "Part 1: " << part1 << std::endl;
out << "Part 2: " << part2 << std::endl;
}

View File

@ -36,16 +36,16 @@ TEST_SUITE("documented examples") {
}
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto machine = Machine{ParseStream(in)};
std::cout << "Part 1: " << Compute(machine, 12, 2) << std::endl;
out << "Part 1: " << Compute(machine, 12, 2) << std::endl;
for (std::int64_t i = 0; i < 100; i++) {
for (std::int64_t j = 0; j < 100; j++) {
if (19690720 == Compute(machine, i, j)) {
std::cout << "Part 2: " << 100 * i + j << std::endl;
out << "Part 2: " << 100 * i + j << std::endl;
}
}
}

View File

@ -66,7 +66,7 @@ auto Record (
} // namespace
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
std::string line;
std::getline(in, line);
@ -88,6 +88,6 @@ auto Main(std::istream & in) -> void
}
}
std::cout << "Part 1: " << part1 << std::endl;
std::cout << "Part 2: " << part2 << std::endl;
out << "Part 1: " << part1 << std::endl;
out << "Part 2: " << part2 << std::endl;
}

View File

@ -43,7 +43,7 @@ auto Valid2(std::string const& str) {
} // namespace
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto const [lo,hi] = Parse(in);
@ -58,6 +58,6 @@ auto Main(std::istream & in) -> void
}
}
std::cout << "Part 1: " << part1 << std::endl;
std::cout << "Part 2: " << part2 << std::endl;
out << "Part 1: " << part1 << std::endl;
out << "Part 2: " << part2 << std::endl;
}

View File

@ -17,9 +17,9 @@ auto Compute(Machine machine, ValueType d) -> ValueType {
} // namespace
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto machine = Machine{ParseStream(in)};
std::cout << "Part 1: " << Compute(machine, 1) << std::endl;
std::cout << "Part 2: " << Compute(std::move(machine), 5) << std::endl;
out << "Part 1: " << Compute(machine, 1) << std::endl;
out << "Part 2: " << Compute(std::move(machine), 5) << std::endl;
}

View File

@ -88,9 +88,9 @@ TEST_SUITE("documented examples") {
}
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto const parents {Parse(in)};
std::cout << "Part 1: " << Part1(parents) << std::endl;
std::cout << "Part 2: " << Part2(parents) << std::endl;
out << "Part 1: " << Part1(parents) << std::endl;
out << "Part 2: " << Part2(parents) << std::endl;
}

View File

@ -85,9 +85,9 @@ TEST_SUITE("documented examples") {
}
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto machine = Machine{ParseStream(in)};
std::cout << "Part 1: " << Part1(machine) << std::endl;
std::cout << "Part 2: " << Part2(std::move(machine)) << std::endl;
out << "Part 1: " << Part1(machine) << std::endl;
out << "Part 2: " << Part2(std::move(machine)) << std::endl;
}

View File

@ -45,21 +45,21 @@ auto Flatten(std::string const& line) {
return merged;
}
auto Draw(std::string const& picture) {
auto Draw(std::ostream & out, std::string const& picture) {
for (std::size_t y = 0; y < 6; y++) {
for (std::size_t x = 0; x < 25; x++) {
std::cout << ('1' == picture[y*25+x] ? "" : "");
out << ('1' == picture[y*25+x] ? "" : "");
}
std::cout << std::endl;
out << std::endl;
}
}
} // namespace
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
std::string line;
std::getline(in, line);
std::cout << "Part 1: " << Part1(line) << std::endl;
Draw(Flatten(line));
out << "Part 1: " << Part1(line) << std::endl;
Draw(out, Flatten(line));
}

View File

@ -29,9 +29,9 @@ TEST_SUITE("documented examples") {
}
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto machine = Machine{ParseStream(in)};
std::cout << "Part 1: " << Compute(machine, 1) << std::endl;
std::cout << "Part 2: " << Compute(std::move(machine), 2) << std::endl;
out << "Part 1: " << Compute(machine, 1) << std::endl;
out << "Part 2: " << Compute(std::move(machine), 2) << std::endl;
}

View File

@ -208,10 +208,10 @@ TEST_SUITE("documented examples") {
}
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto const grid {Grid::Parse(in)};
auto const [part1, base] = Part1(grid);
std::cout << "Part 1: " << part1 << std::endl;
std::cout << "Part 2: " << Part2(grid, base, 200) << std::endl;
out << "Part 1: " << part1 << std::endl;
out << "Part 2: " << Part2(grid, base, 200) << std::endl;
}

View File

@ -37,9 +37,9 @@ auto Compute(Machine machine, ValueType start)
} // namespace
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto machine = Machine{ParseStream(in)};
std::cout << "Part 1: " << Compute(machine, 0).size() << "\nPart 2\n";
Draw(std::cout, Compute(std::move(machine), 1));
out << "Part 1: " << Compute(machine, 0).size() << "\nPart 2\n";
Draw(out, Compute(std::move(machine), 1));
}

View File

@ -93,12 +93,12 @@ auto Part2(std::array<std::vector<Particle>, 3> const& ps) {
} // namespace
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto ps = Parse(in);
auto const part2 = Part2(ps);
auto const part1 = Part1(std::move(ps), 1000);
std::cout << "Part 1: " << part1 << std::endl;
std::cout << "Part 2: " << part2 << std::endl;
out << "Part 1: " << part1 << std::endl;
out << "Part 2: " << part2 << std::endl;
}

View File

@ -59,9 +59,9 @@ auto Compute2(Machine machine) {
} // namespace
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto machine = Machine{ParseStream(in)};
std::cout << "Part 1: " << Compute1(machine) << std::endl;
std::cout << "Part 2: " << Compute2(std::move(machine)) << std::endl;
out << "Part 1: " << Compute1(machine) << std::endl;
out << "Part 2: " << Compute2(std::move(machine)) << std::endl;
}

View File

@ -228,12 +228,12 @@ TEST_SUITE("documented examples") {
}
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto const recipes {Parse(in)};
auto machine {Machine(recipes)};
auto const part1 {machine(1)};
auto const part2 {ComputeFuel(machine, 1'000'000'000'000)};
std::cout << "Part 1: " << part1 << std::endl;
std::cout << "Part 2: " << part2 << std::endl;
out << "Part 1: " << part1 << std::endl;
out << "Part 2: " << part2 << std::endl;
}

View File

@ -92,9 +92,9 @@ auto Compute(std::map<Coord, ValueType> world) -> std::pair<int, int> {
} // namespace
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto const [p1,p2] = Compute(Explore(Machine{ParseStream(in)}));
std::cout << "Part 1: " << p1 << std::endl;
std::cout << "Part 2: " << p2 << std::endl;
out << "Part 1: " << p1 << std::endl;
out << "Part 2: " << p2 << std::endl;
}

View File

@ -118,10 +118,10 @@ TEST_SUITE("documented examples") {
}
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto const input = Parse(in);
std::cout << "Part 1: " << Compute(input, 100, 0) << std::endl;
std::cout << "Part 2: " << Part2(input) << std::endl;
out << "Part 1: " << Compute(input, 100, 0) << std::endl;
out << "Part 2: " << Part2(input) << std::endl;
}

View File

@ -213,15 +213,15 @@ auto GatherScore(Machine m, std::string const& program) -> ValueType {
} // namespace
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto machine = Machine{ParseStream(in)};
auto const grid = GatherOutput(machine);
auto const part1 = ScaffoldAlignments(grid);
auto const path = ComputePath(grid);
auto const program = ComputeProgram(path);
std::cout << "Part 1: " << part1 << std::endl;
out << "Part 1: " << part1 << std::endl;
auto const part2 = GatherScore(std::move(machine), program);
std::cout << "Part 2: " << part2 << std::endl;
out << "Part 2: " << part2 << std::endl;
}

View File

@ -160,14 +160,14 @@ auto Part2(Grid & grid, Features & features) {
} // namespace
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto grid = Grid::Parse(in);
auto features = FindFeatures(grid);
auto distances = FindDistances(grid, features);
std::cout << "Part 1: " << SolveMaze(distances, "@") << std::endl;
out << "Part 1: " << SolveMaze(distances, "@") << std::endl;
Part2(grid, features);
distances = FindDistances(grid, features);
std::cout << "Part 2: " << SolveMaze(distances, "^&*$") << std::endl;
out << "Part 2: " << SolveMaze(distances, "^&*$") << std::endl;
}

View File

@ -45,9 +45,9 @@ auto Part2(Scanner const& scanner) {
} // namespace
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto const scanner = Scanner{Machine{ParseStream(in)}};
std::cout << "Part 1: " << Part1(scanner) << std::endl;
std::cout << "Part 2: " << Part2(scanner) << std::endl;
out << "Part 1: " << Part1(scanner) << std::endl;
out << "Part 2: " << Part2(scanner) << std::endl;
}

View File

@ -275,12 +275,12 @@ TEST_SUITE("2019-20 examples") {
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto const map {Grid::Parse(in)};
auto const portals {FindPortals(map)};
auto const distances {FindDistances(map, portals)};
std::cout << "Part 1: " << SolveMaze(distances, false) << std::endl;
std::cout << "Part 2: " << SolveMaze(distances, true) << std::endl;
out << "Part 1: " << SolveMaze(distances, false) << std::endl;
out << "Part 2: " << SolveMaze(distances, true) << std::endl;
}

View File

@ -229,9 +229,9 @@ auto Compute(
auto const output = RunStream(machine, in, out);
if (output > 0) {
std::cout << "Hull damage: " << output << std::endl;
out << "Hull damage: " << output << std::endl;
} else {
std::cout << "Learned " << GetCounterExample(out) << std::endl;
out << "Learned " << GetCounterExample(out) << std::endl;
}
std::vector<std::vector<std::size_t>> sensors {{}};
@ -243,13 +243,13 @@ auto Compute(
searching = false;
for (bool const p : {true,false}) {
auto const terms = QuineMcCluskey(p, sensor.size(), cases);
std::cout << (p ? "\nTRUE\n" : "\nFALSE\n");
out << (p ? "\nTRUE\n" : "\nFALSE\n");
for (auto const s : sensor) {
std::cout << char('A'+s-1);
out << char('A'+s-1);
}
std::cout << std::endl;
out << std::endl;
for (auto const& term : terms) {
std::cout << term << std::endl;
out << term << std::endl;
}
}
});
@ -262,7 +262,7 @@ auto Compute(
} // namespace
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
Machine machine {ParseStream(in)};

View File

@ -114,15 +114,15 @@ auto Many(Shuffle<Cards> shuffle, unsigned long n) -> Shuffle<Cards> {
} // namespace
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto const instructions {Parse(in)};
auto const shuffle1 {FollowInstructions<10007>(instructions)};
std::cout << "Part 1: " << shuffle1(2019) << std::endl;
out << "Part 1: " << shuffle1(2019) << std::endl;
auto shuffle2 {FollowInstructions<119315717514047>(instructions)};
shuffle2 = Many(shuffle2, 101741582076661);
shuffle2 = shuffle2.inverse();
std::cout << "Part 2: " << shuffle2(2020) << std::endl;
out << "Part 2: " << shuffle2(2020) << std::endl;
}

View File

@ -55,7 +55,7 @@ auto Interact(Ethernet & ethernet, Machine & m, std::optional<Payload> p) -> voi
} // namespace
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto machines = BuildNetwork(Machine{ParseStream(in)});
auto ethernet = Ethernet{};
@ -85,6 +85,6 @@ auto Main(std::istream & in) -> void
}
}
std::cout << "Part 1: " << *part1 << std::endl;
std::cout << "Part 2: " << *part2 << std::endl;
out << "Part 1: " << *part1 << std::endl;
out << "Part 2: " << *part2 << std::endl;
}

View File

@ -135,9 +135,9 @@ TEST_SUITE("documented examples") {
}
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto const bugs {FindBugs(Grid::Parse(in))};
std::cout << "Part 1: " << Part1(bugs) << std::endl;
std::cout << "Part 2: " << Part2(std::move(bugs), 200) << std::endl;
out << "Part 1: " << Part1(bugs) << std::endl;
out << "Part 2: " << Part2(std::move(bugs), 200) << std::endl;
}

View File

@ -15,6 +15,7 @@ using namespace intcode;
namespace {
auto RunWithIO(
std::ostream & out,
Machine m,
std::string const& input
) -> void
@ -25,7 +26,7 @@ auto RunWithIO(
if (it < input.end()) { return *it++; }
throw std::runtime_error{"insufficient input"};
},
[&](ValueType o) { std::cout << char(o); });
[&](ValueType o) { out << char(o); });
}
auto Search(std::string & script)
@ -58,7 +59,7 @@ auto Search(std::string & script)
} // namespace
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
std::string script =
"north\n" "take sand\n"
@ -77,5 +78,5 @@ auto Main(std::istream & in) -> void
Search(script);
RunWithIO(Machine{ParseStream(in)}, script);
RunWithIO(out, Machine{ParseStream(in)}, script);
}

View File

@ -78,9 +78,9 @@ TEST_CASE("part 2") {
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto const entries {Parse(in)};
std::cout << "Part 1: " << Part1(entries) << std::endl;
std::cout << "Part 2: " << Part2(entries) << std::endl;
out << "Part 1: " << Part1(entries) << std::endl;
out << "Part 2: " << Part2(entries) << std::endl;
}

View File

@ -56,7 +56,7 @@ TEST_CASE("part 2") {
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
std::uint64_t part1{}, part2{};
@ -66,6 +66,6 @@ auto Main(std::istream & in) -> void
if (Part1(entry)) part1++;
if (Part2(entry)) part2++;
}
std::cout << "Part 1: " << part1 << std::endl;
std::cout << "Part 2: " << part2 << std::endl;
out << "Part 1: " << part1 << std::endl;
out << "Part 2: " << part2 << std::endl;
}

View File

@ -76,9 +76,9 @@ TEST_CASE("part 2") {
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto const grid {Grid::Parse(in)};
std::cout << "Part 1: " << Part1(grid) << std::endl;
std::cout << "Part 2: " << Part2(grid) << std::endl;
out << "Part 1: " << Part1(grid) << std::endl;
out << "Part 2: " << Part2(grid) << std::endl;
}

View File

@ -75,9 +75,9 @@ TEST_CASE("part 2") {
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto const adapters {Parse(in)};
std::cout << "Part 1: " << Part1(adapters) << std::endl;
std::cout << "Part 2: " << Part2(adapters) << std::endl;
out << "Part 1: " << Part1(adapters) << std::endl;
out << "Part 2: " << Part2(adapters) << std::endl;
}

View File

@ -184,9 +184,9 @@ TEST_SUITE("documented examples") {
}
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto input {Parse(in)};
std::cout << "Part 1: " << Part1(input) << std::endl;
std::cout << "Part 2: " << Part2(input) << std::endl;
out << "Part 1: " << Part1(input) << std::endl;
out << "Part 2: " << Part2(input) << std::endl;
}

View File

@ -140,7 +140,7 @@ TEST_CASE("errors") {
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
std::int64_t part1 = 0;
std::int64_t part2 = 0;
@ -151,6 +151,6 @@ auto Main(std::istream & in) -> void
part2 += Part2(line);
}
std::cout << "Part 1: " << part1 << std::endl;
std::cout << "Part 2: " << part2 << std::endl;
out << "Part 1: " << part1 << std::endl;
out << "Part 2: " << part2 << std::endl;
}

View File

@ -178,9 +178,9 @@ TEST_CASE("part 2") {
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto const input {Parse(in)};
std::cout << "Part 1: " << Part1(input) << std::endl;
std::cout << "Part 2: " << Part2(input) << std::endl;
out << "Part 1: " << Part1(input) << std::endl;
out << "Part 2: " << Part2(input) << std::endl;
}

View File

@ -84,9 +84,9 @@ TEST_SUITE("2022-01 examples") {
}
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto const [p1,p2] = Solve(Parse(in));
std::cout << "Part 1: " << p1 << std::endl;
std::cout << "Part 2: " << p2 << std::endl;
out << "Part 1: " << p1 << std::endl;
out << "Part 2: " << p2 << std::endl;
}

View File

@ -136,9 +136,9 @@ C Z
}
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto const input {Parse(in)} ;
std::cout << "Part 1: " << Part1(input) << std::endl;
std::cout << "Part 2: " << Part2(input) << std::endl;
out << "Part 1: " << Part1(input) << std::endl;
out << "Part 2: " << Part2(input) << std::endl;
}

View File

@ -97,9 +97,9 @@ TEST_SUITE("2022-03 examples") {
}
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto input {Parse(in)};
std::cout << "Part 1: " << Part1(input) << std::endl;
std::cout << "Part 2: " << Part2(input) << std::endl;
out << "Part 1: " << Part1(input) << std::endl;
out << "Part 2: " << Part2(input) << std::endl;
}

View File

@ -48,9 +48,9 @@ TEST_SUITE("2022-04 examples") {
}
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto const [p1,p2] = Solve(in);
std::cout << "Part 1: " << p1 << std::endl;
std::cout << "Part 2: " << p2 << std::endl;
out << "Part 1: " << p1 << std::endl;
out << "Part 2: " << p2 << std::endl;
}

View File

@ -57,10 +57,10 @@ TEST_SUITE("2022-06 examples") {
}
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
std::string input;
std::getline(in, input);
std::cout << "Part 1: " << Solve(input, 4) << std::endl;
std::cout << "Part 2: " << Solve(input, 14) << std::endl;
out << "Part 1: " << Solve(input, 4) << std::endl;
out << "Part 2: " << Solve(input, 14) << std::endl;
}

View File

@ -71,9 +71,9 @@ TEST_SUITE("2022-08 examples") {
}
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto const grid = Grid::Parse(in);
std::cout << "Part 1: " << Part1(grid) << std::endl;
std::cout << "Part 2: " << Part2(grid) << std::endl;
out << "Part 1: " << Part1(grid) << std::endl;
out << "Part 2: " << Part2(grid) << std::endl;
}

View File

@ -97,9 +97,9 @@ TEST_SUITE("2022-09 examples") {
}
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto const [p1,p2] = Solve(in);
std::cout << "Part 1: " << p1 << std::endl;
std::cout << "Part 2: " << p2 << std::endl;
out << "Part 1: " << p1 << std::endl;
out << "Part 2: " << p2 << std::endl;
}

View File

@ -96,9 +96,9 @@ TEST_SUITE("2022-10 examples") {
}
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto const snapshots {Execute(in)};
std::cout << "Part 1: " << Part1(snapshots) << std::endl;
Part2(snapshots, std::cout << "Part 2:\n");
out << "Part 1: " << Part1(snapshots) << std::endl;
Part2(snapshots, out << "Part 2:\n");
}

View File

@ -146,9 +146,9 @@ Monkey 3:
}
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto const input {Parse(in)};
std::cout << "Part 1: " << Part1(input) << std::endl;
std::cout << "Part 2: " << Part2(input) << std::endl;
out << "Part 1: " << Part1(input) << std::endl;
out << "Part 2: " << Part2(input) << std::endl;
}

View File

@ -84,9 +84,9 @@ TEST_SUITE("2022-12 examples") {
}
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto const [start, end, grid] = Parse(in);
std::cout << "Part 1: " << Solve({start}, end, grid) << std::endl;
std::cout << "Part 2: " << Solve(Part2Starts(grid), end, grid) << std::endl;
out << "Part 1: " << Solve({start}, end, grid) << std::endl;
out << "Part 2: " << Solve(Part2Starts(grid), end, grid) << std::endl;
}

View File

@ -140,10 +140,10 @@ TEST_SUITE("2022-13 examples") {
}
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto input = Parse(in);
std::cout << "count " << input.size() << std::endl;
std::cout << "Part 1: " << Part1(input) << std::endl;
std::cout << "Part 2: " << Part2(std::move(input)) << std::endl;
out << "count " << input.size() << std::endl;
out << "Part 1: " << Part1(input) << std::endl;
out << "Part 2: " << Part2(std::move(input)) << std::endl;
}

View File

@ -334,12 +334,12 @@ Valve JJ has flow rate=21; tunnel leads to valve II
/// @brief Print solutions to parts 1 and 2
/// @param in selected input stream
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto rooms = Parse(in);
auto const n = FlowsFirst(rooms);
auto const [start, distances] = GenerateDistances(rooms);
rooms.resize(n);
std::cout << "Part 1: " << Part1(start, rooms, distances) << std::endl;
std::cout << "Part 2: " << Part2(start, rooms, distances) << std::endl;
out << "Part 1: " << Part1(start, rooms, distances) << std::endl;
out << "Part 2: " << Part2(start, rooms, distances) << std::endl;
}

View File

@ -96,9 +96,9 @@ TEST_SUITE("2022-12 examples") {
}
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto const obj {Parse(in)};
std::cout << "Part 1: " << Part1(obj) << std::endl;
std::cout << "Part 2: " << Part2(obj) << std::endl;
out << "Part 1: " << Part1(obj) << std::endl;
out << "Part 2: " << Part2(obj) << std::endl;
}

View File

@ -108,9 +108,9 @@ TEST_SUITE("2022-20 examples") {
}
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
auto input {Parse(in)};
std::cout << "Part 1: " << Part1(input) << std::endl;
std::cout << "Part 2: " << Part2(std::move(input)) << std::endl;
out << "Part 1: " << Part1(input) << std::endl;
out << "Part 2: " << Part2(std::move(input)) << std::endl;
}

View File

@ -87,7 +87,7 @@ TEST_SUITE("2022-25 examples") {
}
}
auto Main(std::istream & in) -> void
auto Main(std::istream & in, std::ostream & out) -> void
{
std::cout << "Part 1: " << Solve(in) << std::endl;
out << "Part 1: " << Solve(in) << std::endl;
}

View File

@ -17,6 +17,6 @@ auto Startup(int argc, char ** argv) -> std::unique_ptr<std::istream, void(*)(st
}
auto Main(std::istream & in) -> void;
auto Main(std::istream & in, std::ostream & out) -> void;
#endif

View File

@ -33,7 +33,7 @@ auto Startup(int argc, char ** argv) -> std::unique_ptr<std::istream, void(*)(st
auto main(int argc, char ** argv) -> int
{
try {
Main(*aocpp::Startup(argc, argv));
Main(*aocpp::Startup(argc, argv), std::cout);
} catch (std::exception const& e) {
std::cerr << "Program failed: " << e.what() << std::endl;
return 1;