diff --git a/2017/01.cpp b/2017/01.cpp index 751683e..e160276 100644 --- a/2017/01.cpp +++ b/2017/01.cpp @@ -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; } diff --git a/2017/02.cpp b/2017/02.cpp index fbf78f7..7352f4e 100644 --- a/2017/02.cpp +++ b/2017/02.cpp @@ -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; } diff --git a/2017/05.cpp b/2017/05.cpp index 5ae5b11..3da152c 100644 --- a/2017/05.cpp +++ b/2017/05.cpp @@ -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; } diff --git a/2017/06.cpp b/2017/06.cpp index 2531b61..9da8fa2 100644 --- a/2017/06.cpp +++ b/2017/06.cpp @@ -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; } diff --git a/2017/10.cpp b/2017/10.cpp index 716c9ec..499a9e6 100644 --- a/2017/10.cpp +++ b/2017/10.cpp @@ -9,7 +9,7 @@ #include #include -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; } diff --git a/2017/11.cpp b/2017/11.cpp index 52add10..318bb63 100644 --- a/2017/11.cpp +++ b/2017/11.cpp @@ -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; } diff --git a/2017/12.cpp b/2017/12.cpp index 71206c6..48dace1 100644 --- a/2017/12.cpp +++ b/2017/12.cpp @@ -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; } diff --git a/2017/13.cpp b/2017/13.cpp index 8db6965..540954c 100644 --- a/2017/13.cpp +++ b/2017/13.cpp @@ -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; } diff --git a/2017/14.cpp b/2017/14.cpp index 847d4ee..6c71d90 100644 --- a/2017/14.cpp +++ b/2017/14.cpp @@ -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; } diff --git a/2017/17.cpp b/2017/17.cpp index ce42cbf..a65d20b 100644 --- a/2017/17.cpp +++ b/2017/17.cpp @@ -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; } diff --git a/2017/18.cpp b/2017/18.cpp index 7f92e4f..d1785a7 100644 --- a/2017/18.cpp +++ b/2017/18.cpp @@ -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; } diff --git a/2017/19.cpp b/2017/19.cpp index 9e61eab..cb40ffd 100644 --- a/2017/19.cpp +++ b/2017/19.cpp @@ -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; } diff --git a/2018/15.cpp b/2018/15.cpp index c6f8c1f..80f9175 100644 --- a/2018/15.cpp +++ b/2018/15.cpp @@ -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; } diff --git a/2019/01.cpp b/2019/01.cpp index ddcb2f4..8f51dc4 100644 --- a/2019/01.cpp +++ b/2019/01.cpp @@ -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; } diff --git a/2019/02.cpp b/2019/02.cpp index 0e4221f..307587d 100644 --- a/2019/02.cpp +++ b/2019/02.cpp @@ -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; } } } diff --git a/2019/03.cpp b/2019/03.cpp index 2d66fb2..32faaf8 100644 --- a/2019/03.cpp +++ b/2019/03.cpp @@ -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; } diff --git a/2019/04.cpp b/2019/04.cpp index 220e642..fe9b150 100644 --- a/2019/04.cpp +++ b/2019/04.cpp @@ -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; } diff --git a/2019/05.cpp b/2019/05.cpp index 982f775..63ea632 100644 --- a/2019/05.cpp +++ b/2019/05.cpp @@ -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; } diff --git a/2019/06.cpp b/2019/06.cpp index 1b4c0b6..877828d 100644 --- a/2019/06.cpp +++ b/2019/06.cpp @@ -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; } diff --git a/2019/07.cpp b/2019/07.cpp index 8f9d5d7..75d73b2 100644 --- a/2019/07.cpp +++ b/2019/07.cpp @@ -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; } diff --git a/2019/08.cpp b/2019/08.cpp index c8dda9e..d309b0a 100644 --- a/2019/08.cpp +++ b/2019/08.cpp @@ -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)); } diff --git a/2019/09.cpp b/2019/09.cpp index c9520f9..c4bd706 100644 --- a/2019/09.cpp +++ b/2019/09.cpp @@ -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; } diff --git a/2019/10.cpp b/2019/10.cpp index 007a04d..f933c76 100644 --- a/2019/10.cpp +++ b/2019/10.cpp @@ -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; } diff --git a/2019/11.cpp b/2019/11.cpp index fe948fe..2bf1d4c 100644 --- a/2019/11.cpp +++ b/2019/11.cpp @@ -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)); } diff --git a/2019/12.cpp b/2019/12.cpp index 5df8a95..c74b378 100644 --- a/2019/12.cpp +++ b/2019/12.cpp @@ -93,12 +93,12 @@ auto Part2(std::array, 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; } diff --git a/2019/13.cpp b/2019/13.cpp index 03de0fd..d8261c3 100644 --- a/2019/13.cpp +++ b/2019/13.cpp @@ -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; } diff --git a/2019/14.cpp b/2019/14.cpp index cf5640c..5ac18b8 100644 --- a/2019/14.cpp +++ b/2019/14.cpp @@ -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; } diff --git a/2019/15.cpp b/2019/15.cpp index 5c5929c..ef14da4 100644 --- a/2019/15.cpp +++ b/2019/15.cpp @@ -92,9 +92,9 @@ auto Compute(std::map world) -> std::pair { } // 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; } diff --git a/2019/16.cpp b/2019/16.cpp index 397124c..dd970dd 100644 --- a/2019/16.cpp +++ b/2019/16.cpp @@ -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; } diff --git a/2019/17.cpp b/2019/17.cpp index fc14455..2b76050 100644 --- a/2019/17.cpp +++ b/2019/17.cpp @@ -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; } diff --git a/2019/18.cpp b/2019/18.cpp index 0a62af0..59fd2fa 100644 --- a/2019/18.cpp +++ b/2019/18.cpp @@ -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; } diff --git a/2019/19.cpp b/2019/19.cpp index a9a6b8c..bdd0f4f 100644 --- a/2019/19.cpp +++ b/2019/19.cpp @@ -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; } diff --git a/2019/20.cpp b/2019/20.cpp index ed64530..9f25b92 100644 --- a/2019/20.cpp +++ b/2019/20.cpp @@ -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; } diff --git a/2019/21.cpp b/2019/21.cpp index a52c5e9..d0921e3 100644 --- a/2019/21.cpp +++ b/2019/21.cpp @@ -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> 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)}; diff --git a/2019/22.cpp b/2019/22.cpp index e680250..001784a 100644 --- a/2019/22.cpp +++ b/2019/22.cpp @@ -114,15 +114,15 @@ auto Many(Shuffle shuffle, unsigned long n) -> Shuffle { } // 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; } diff --git a/2019/23.cpp b/2019/23.cpp index 9b90ea6..92d1ffb 100644 --- a/2019/23.cpp +++ b/2019/23.cpp @@ -55,7 +55,7 @@ auto Interact(Ethernet & ethernet, Machine & m, std::optional 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; } diff --git a/2019/24.cpp b/2019/24.cpp index f20aedc..7bd1113 100644 --- a/2019/24.cpp +++ b/2019/24.cpp @@ -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; } diff --git a/2019/25.cpp b/2019/25.cpp index 06c2ccf..4dfa560 100644 --- a/2019/25.cpp +++ b/2019/25.cpp @@ -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); } diff --git a/2020/01.cpp b/2020/01.cpp index 92c8d9b..748674a 100644 --- a/2020/01.cpp +++ b/2020/01.cpp @@ -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; } diff --git a/2020/02.cpp b/2020/02.cpp index 8ea8c59..c8b5c07 100644 --- a/2020/02.cpp +++ b/2020/02.cpp @@ -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; } diff --git a/2020/03.cpp b/2020/03.cpp index 2c943cf..c431d76 100644 --- a/2020/03.cpp +++ b/2020/03.cpp @@ -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; } diff --git a/2020/10.cpp b/2020/10.cpp index fdffed6..98ddb6c 100644 --- a/2020/10.cpp +++ b/2020/10.cpp @@ -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; } diff --git a/2020/16.cpp b/2020/16.cpp index 033024d..74359a4 100644 --- a/2020/16.cpp +++ b/2020/16.cpp @@ -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; } diff --git a/2020/18.cpp b/2020/18.cpp index 610bbcc..0af916f 100644 --- a/2020/18.cpp +++ b/2020/18.cpp @@ -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; } diff --git a/2020/21.cpp b/2020/21.cpp index a39e50d..d0684e5 100644 --- a/2020/21.cpp +++ b/2020/21.cpp @@ -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; } diff --git a/2022/01.cpp b/2022/01.cpp index 83db33b..5fdd090 100644 --- a/2022/01.cpp +++ b/2022/01.cpp @@ -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; } diff --git a/2022/02.cpp b/2022/02.cpp index e2ac5a9..e014ee2 100644 --- a/2022/02.cpp +++ b/2022/02.cpp @@ -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; } diff --git a/2022/03.cpp b/2022/03.cpp index 8da471c..ffe8d83 100644 --- a/2022/03.cpp +++ b/2022/03.cpp @@ -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; } diff --git a/2022/04.cpp b/2022/04.cpp index cac7e30..22fd898 100644 --- a/2022/04.cpp +++ b/2022/04.cpp @@ -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; } diff --git a/2022/06.cpp b/2022/06.cpp index a27d981..b4905be 100644 --- a/2022/06.cpp +++ b/2022/06.cpp @@ -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; } diff --git a/2022/08.cpp b/2022/08.cpp index b477d2d..7a9c116 100644 --- a/2022/08.cpp +++ b/2022/08.cpp @@ -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; } diff --git a/2022/09.cpp b/2022/09.cpp index 9d9d058..cb82686 100644 --- a/2022/09.cpp +++ b/2022/09.cpp @@ -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; } diff --git a/2022/10.cpp b/2022/10.cpp index 489d75f..a5176a6 100644 --- a/2022/10.cpp +++ b/2022/10.cpp @@ -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"); } diff --git a/2022/11.cpp b/2022/11.cpp index 2c28202..e2722a8 100644 --- a/2022/11.cpp +++ b/2022/11.cpp @@ -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; } diff --git a/2022/12.cpp b/2022/12.cpp index 6dde7f0..bd5e6f4 100644 --- a/2022/12.cpp +++ b/2022/12.cpp @@ -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; } diff --git a/2022/13.cpp b/2022/13.cpp index ae2c1f1..b8320c7 100644 --- a/2022/13.cpp +++ b/2022/13.cpp @@ -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; } diff --git a/2022/16.cpp b/2022/16.cpp index e5e9f97..5b84125 100644 --- a/2022/16.cpp +++ b/2022/16.cpp @@ -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; } diff --git a/2022/18.cpp b/2022/18.cpp index 3834643..9a98b0e 100644 --- a/2022/18.cpp +++ b/2022/18.cpp @@ -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; } diff --git a/2022/20.cpp b/2022/20.cpp index a004263..226473a 100644 --- a/2022/20.cpp +++ b/2022/20.cpp @@ -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; } diff --git a/2022/25.cpp b/2022/25.cpp index 0e7bedc..903fa0f 100644 --- a/2022/25.cpp +++ b/2022/25.cpp @@ -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; } diff --git a/lib/include/aocpp/Startup.hpp b/lib/include/aocpp/Startup.hpp index d84305c..a13b68d 100644 --- a/lib/include/aocpp/Startup.hpp +++ b/lib/include/aocpp/Startup.hpp @@ -17,6 +17,6 @@ auto Startup(int argc, char ** argv) -> std::unique_ptr void; +auto Main(std::istream & in, std::ostream & out) -> void; #endif diff --git a/lib/src/Startup.cpp b/lib/src/Startup.cpp index 590103b..15a3d0f 100644 --- a/lib/src/Startup.cpp +++ b/lib/src/Startup.cpp @@ -33,7 +33,7 @@ auto Startup(int argc, char ** argv) -> std::unique_ptr 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;