Use a common main

This commit is contained in:
Eric Mertens
2023-01-31 08:58:42 -08:00
parent 542ccc7884
commit c6264a2a1b
63 changed files with 222 additions and 174 deletions

View File

@@ -84,8 +84,9 @@ TEST_SUITE("2022-01 examples") {
}
}
auto main(int argc, char** argv) -> int {
auto const [p1,p2] = Solve(Parse(*aocpp::Startup(argc, argv)));
auto Main(std::istream & in) -> void
{
auto const [p1,p2] = Solve(Parse(in));
std::cout << "Part 1: " << p1 << std::endl;
std::cout << "Part 2: " << p2 << std::endl;
}

View File

@@ -136,8 +136,9 @@ C Z
}
}
auto main(int argc, char** argv) -> int {
auto const input {Parse(*aocpp::Startup(argc, argv))} ;
auto Main(std::istream & in) -> void
{
auto const input {Parse(in)} ;
std::cout << "Part 1: " << Part1(input) << std::endl;
std::cout << "Part 2: " << Part2(input) << std::endl;
}

View File

@@ -97,8 +97,9 @@ TEST_SUITE("2022-03 examples") {
}
}
auto main(int argc, char** argv) -> int {
auto input = Parse(*aocpp::Startup(argc, argv));
auto Main(std::istream & in) -> void
{
auto input {Parse(in)};
std::cout << "Part 1: " << Part1(input) << std::endl;
std::cout << "Part 2: " << Part2(input) << std::endl;
}

View File

@@ -48,8 +48,9 @@ TEST_SUITE("2022-04 examples") {
}
}
auto main(int argc, char** argv) -> int {
auto [p1,p2] = Solve(*aocpp::Startup(argc, argv));
auto Main(std::istream & in) -> void
{
auto const [p1,p2] = Solve(in);
std::cout << "Part 1: " << p1 << std::endl;
std::cout << "Part 2: " << p2 << std::endl;
}

View File

@@ -57,9 +57,10 @@ TEST_SUITE("2022-06 examples") {
}
}
auto main(int argc, char** argv) -> int {
auto Main(std::istream & in) -> void
{
std::string input;
std::getline(*aocpp::Startup(argc, argv), input);
std::cout << "Part 1: " << Solve(input, 4) << std::endl;
std::getline(in, input);
std::cout << "Part 1: " << Solve(input, 4) << std::endl;
std::cout << "Part 2: " << Solve(input, 14) << std::endl;
}

View File

@@ -41,8 +41,7 @@ auto Part2(Grid const& grid) -> std::int64_t
grid.each([&](Coord const c, char const v) {
auto score = std::transform_reduce(
std::begin(directions), std::end(directions),
std::int64_t{1},
std::multiplies(),
std::int64_t{1}, std::multiplies(), // product
[&](Dir const dir) {
std::int64_t count {0};
for (auto x = dir(c); grid.contains(x); x = dir(x)) {
@@ -72,9 +71,9 @@ TEST_SUITE("2022-08 examples") {
}
}
auto main(int argc, char** argv) -> int
auto Main(std::istream & in) -> void
{
auto grid = Grid::Parse(*aocpp::Startup(argc, argv));
auto const grid = Grid::Parse(in);
std::cout << "Part 1: " << Part1(grid) << std::endl;
std::cout << "Part 2: " << Part2(grid) << std::endl;
}

View File

@@ -97,9 +97,9 @@ TEST_SUITE("2022-09 examples") {
}
}
auto main(int argc, char** argv) -> int
auto Main(std::istream & in) -> void
{
auto [p1,p2] = Solve(*aocpp::Startup(argc, argv));
auto const [p1,p2] = Solve(in);
std::cout << "Part 1: " << p1 << std::endl;
std::cout << "Part 2: " << p2 << std::endl;
}

View File

@@ -96,9 +96,9 @@ TEST_SUITE("2022-10 examples") {
}
}
auto main(int argc, char** argv) -> int
auto Main(std::istream & in) -> void
{
auto snapshots = Execute(*aocpp::Startup(argc, argv));
auto const snapshots {Execute(in)};
std::cout << "Part 1: " << Part1(snapshots) << std::endl;
Part2(snapshots, std::cout << "Part 2:\n");
}

View File

@@ -146,9 +146,9 @@ Monkey 3:
}
}
auto main(int argc, char** argv) -> int
auto Main(std::istream & in) -> void
{
auto const input = Parse(*aocpp::Startup(argc, argv));
auto const input {Parse(in)};
std::cout << "Part 1: " << Part1(input) << std::endl;
std::cout << "Part 2: " << Part2(input) << std::endl;
}

View File

@@ -84,9 +84,9 @@ TEST_SUITE("2022-12 examples") {
}
}
auto main(int argc, char** argv) -> int
auto Main(std::istream & in) -> void
{
auto [start, end, grid] = Parse(*aocpp::Startup(argc, argv));
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;
}

View File

@@ -140,9 +140,9 @@ TEST_SUITE("2022-13 examples") {
}
}
auto main(int argc, char** argv) -> int
auto Main(std::istream & in) -> void
{
auto input = Parse(*aocpp::Startup(argc, argv));
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;

View File

@@ -332,13 +332,11 @@ Valve JJ has flow rate=21; tunnel leads to valve II
}
}
/// @brief Select input source and print solution to part 1 and 2
/// @param argc Command line argument count
/// @param argv Command line arguments
/// @return 0 on success
auto main(int argc, char** argv) -> int
/// @brief Print solutions to parts 1 and 2
/// @param in selected input stream
auto Main(std::istream & in) -> void
{
auto rooms = Parse(*aocpp::Startup(argc, argv));
auto rooms = Parse(in);
auto const n = FlowsFirst(rooms);
auto const [start, distances] = GenerateDistances(rooms);
rooms.resize(n);

View File

@@ -96,9 +96,9 @@ TEST_SUITE("2022-12 examples") {
}
}
auto main(int argc, char** argv) -> int
auto Main(std::istream & in) -> void
{
auto obj = Parse(*aocpp::Startup(argc, argv));
auto const obj {Parse(in)};
std::cout << "Part 1: " << Part1(obj) << std::endl;
std::cout << "Part 2: " << Part2(obj) << std::endl;
}

View File

@@ -108,8 +108,9 @@ TEST_SUITE("2022-20 examples") {
}
}
auto main(int argc, char** argv) -> int {
auto input = Parse(*aocpp::Startup(argc, argv));
auto Main(std::istream & in) -> void
{
auto input {Parse(in)};
std::cout << "Part 1: " << Part1(input) << std::endl;
std::cout << "Part 2: " << Part2(input) << std::endl;
std::cout << "Part 2: " << Part2(std::move(input)) << std::endl;
}

View File

@@ -87,7 +87,7 @@ TEST_SUITE("2022-25 examples") {
}
}
auto main(int argc, char** argv) -> int
auto Main(std::istream & in) -> void
{
std::cout << "Part 1: " << Solve(*aocpp::Startup(argc, argv)) << std::endl;
std::cout << "Part 1: " << Solve(in) << std::endl;
}