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;
}