diff --git a/2017/01.cpp b/2017/01.cpp index 459b6ae..751683e 100644 --- a/2017/01.cpp +++ b/2017/01.cpp @@ -46,9 +46,10 @@ TEST_SUITE("2017-01 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::getline(in, input); std::cout << "Part 1: " << Part1(input) << std::endl; std::cout << "Part 2: " << Part2(input) << std::endl; } diff --git a/2017/02.cpp b/2017/02.cpp index b97c263..fbf78f7 100644 --- a/2017/02.cpp +++ b/2017/02.cpp @@ -66,10 +66,9 @@ TEST_SUITE("2017-02 examples") { } } -auto main(int argc, char** argv) -> int { - auto in_ptr = aocpp::Startup(argc, argv); - auto & in = *in_ptr; - auto [p1,p2] = Omnibus(in); +auto Main(std::istream & in) -> void +{ + auto const [p1,p2] = Omnibus(in); std::cout << "Part 1: " << p1 << std::endl; std::cout << "Part 2: " << p2 << std::endl; } diff --git a/2017/05.cpp b/2017/05.cpp index be2b288..5ae5b11 100644 --- a/2017/05.cpp +++ b/2017/05.cpp @@ -57,8 +57,9 @@ TEST_SUITE("2017-05 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: " << Run1(input) << std::endl; std::cout << "Part 2: " << Run2(std::move(input)) << std::endl; } diff --git a/2017/06.cpp b/2017/06.cpp index f4db489..2531b61 100644 --- a/2017/06.cpp +++ b/2017/06.cpp @@ -80,9 +80,10 @@ TEST_SUITE("2017-06 examples") { } } -auto main(int argc, char** argv) -> int { - auto input = Parse(*aocpp::Startup(argc, argv)); - auto answer = CycleSearch(input); +auto Main(std::istream & in) -> 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; } diff --git a/2017/10.cpp b/2017/10.cpp index ed22575..716c9ec 100644 --- a/2017/10.cpp +++ b/2017/10.cpp @@ -9,9 +9,10 @@ #include #include -auto main(int argc, char** argv) -> int { +auto Main(std::istream & in) -> void +{ std::string line; - std::getline(*aocpp::Startup(argc, argv), line); + std::getline(in, line); std::vector lengths1; for (auto && x : aocpp::SplitOn(line, ",")) { @@ -22,4 +23,4 @@ auto main(int argc, char** argv) -> int { std::cout << "Part 1: " << long{result[0]} * long{result[1]} << std::endl; std::cout << "Part 2: " << knothash::render(knothash::hash(line)) << std::endl; -} \ No newline at end of file +} diff --git a/2017/11.cpp b/2017/11.cpp index d879964..52add10 100644 --- a/2017/11.cpp +++ b/2017/11.cpp @@ -60,10 +60,11 @@ TEST_SUITE("2017-11 examples") { } } -auto main(int argc, char** argv) -> int { +auto Main(std::istream & in) -> void +{ std::string line; - std::getline(*Startup(argc, argv), line); - auto [part1, part2] = Walk(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; -} \ No newline at end of file +} diff --git a/2017/12.cpp b/2017/12.cpp index 54c83ef..71206c6 100644 --- a/2017/12.cpp +++ b/2017/12.cpp @@ -101,9 +101,10 @@ TEST_SUITE("2017-12 examples") { } } -auto main(int argc, char** argv) -> int { - auto input = Parse(*Startup(argc, argv)); - auto [part1, part2] = LinkNodes(input); +auto Main(std::istream & in) -> 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; -} \ No newline at end of file +} diff --git a/2017/13.cpp b/2017/13.cpp index 682d578..8db6965 100644 --- a/2017/13.cpp +++ b/2017/13.cpp @@ -40,7 +40,7 @@ auto Caught(std::vector const& scanners) -> std::size_t { return severity; } -auto Delay(std::vector & scanners) { +auto Delay(std::vector scanners) { std::uint64_t delay = 0; for (;;) { @@ -72,8 +72,9 @@ TEST_SUITE("2017-12 examples") { } } -auto main(int argc, char** argv) -> int { - auto input = Parse(*Startup(argc, argv)); +auto Main(std::istream & in) -> void +{ + auto input {Parse(in)}; std::cout << "Part 1: " << Caught(input) << std::endl; - std::cout << "Part 2: " << Delay(input) << std::endl; -} \ No newline at end of file + std::cout << "Part 2: " << Delay(std::move(input)) << std::endl; +} diff --git a/2017/14.cpp b/2017/14.cpp index 4418943..847d4ee 100644 --- a/2017/14.cpp +++ b/2017/14.cpp @@ -94,10 +94,11 @@ TEST_CASE("flqrgnkx") { } } -auto main(int argc, char** argv) -> int { +auto Main(std::istream & in) -> void +{ std::string input; - std::getline(*aocpp::Startup(argc, argv), input); - auto rows = MakeRows(std::move(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; -} \ No newline at end of file +} diff --git a/2017/17.cpp b/2017/17.cpp index bab4834..ce42cbf 100644 --- a/2017/17.cpp +++ b/2017/17.cpp @@ -59,9 +59,10 @@ TEST_SUITE("2017-17 examples") { } } -auto main(int argc, char** argv) -> int { +auto Main(std::istream & in) -> void +{ int steps; - *Startup(argc, argv) >> steps; + in >> steps; std::cout << "Part 1: " << Part1(steps, 2017) << std::endl; std::cout << "Part 2: " << Part2(steps, 50'000'000) << std::endl; -} \ No newline at end of file +} diff --git a/2017/18.cpp b/2017/18.cpp index fa35066..7f92e4f 100644 --- a/2017/18.cpp +++ b/2017/18.cpp @@ -237,8 +237,9 @@ TEST_SUITE("documented examples") { } } -auto main(int argc, char** argv) -> int { - auto const program = Parse(*aocpp::Startup(argc, argv)); +auto Main(std::istream & in) -> void +{ + auto const program {Parse(in)}; std::cout << "Part 1: " << Part1(program) << std::endl; std::cout << "Part 2: " << Part2(program) << std::endl; } diff --git a/2017/19.cpp b/2017/19.cpp index 1725a60..9e61eab 100644 --- a/2017/19.cpp +++ b/2017/19.cpp @@ -65,15 +65,15 @@ TEST_SUITE("2017-19 examples") { " +B-+ +--+ \n" " \n" }; - auto [p1,p2] = Drive(Grid::Parse(in)); + auto const [p1, p2] = Drive(Grid::Parse(in)); CHECK(p1 == "ABCDEF"); CHECK(p2 == 38); } } -auto main(int argc, char** argv) -> int { - auto input = Grid::Parse(*aocpp::Startup(argc, argv)); - auto [part1, part2] = Drive(input); +auto Main(std::istream & in) -> void +{ + auto const [part1, part2] = Drive(Grid::Parse(in)); std::cout << "Part 1: " << part1 << std::endl; std::cout << "Part 2: " << part2 << std::endl; } diff --git a/2018/15.cpp b/2018/15.cpp index 5cd2430..c6f8c1f 100644 --- a/2018/15.cpp +++ b/2018/15.cpp @@ -476,8 +476,9 @@ TEST_SUITE("2018-15 examples") { } } -auto main(int argc, char** argv) -> int { - auto grid = Grid::Parse(*aocpp::Startup(argc, argv)); +auto Main(std::istream & in) -> 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; diff --git a/2019/01.cpp b/2019/01.cpp index 75a33f8..ddcb2f4 100644 --- a/2019/01.cpp +++ b/2019/01.cpp @@ -44,10 +44,8 @@ TEST_CASE("part 2") { } -auto main(int argc, char** argv) -> int { - auto in_ptr = aocpp::Startup(argc, argv); - auto & in = *in_ptr; - +auto Main(std::istream & in) -> void +{ std::int64_t weight; std::int64_t part1 = 0; std::int64_t part2 = 0; diff --git a/2019/02.cpp b/2019/02.cpp index 14770f6..0e4221f 100644 --- a/2019/02.cpp +++ b/2019/02.cpp @@ -36,8 +36,9 @@ TEST_SUITE("documented examples") { } } -auto main(int argc, char** argv) -> int { - auto machine = Machine{ParseStream(*aocpp::Startup(argc, argv))}; +auto Main(std::istream & in) -> void +{ + auto machine = Machine{ParseStream(in)}; std::cout << "Part 1: " << Compute(machine, 12, 2) << std::endl; diff --git a/2019/03.cpp b/2019/03.cpp index ae8ffe5..2d66fb2 100644 --- a/2019/03.cpp +++ b/2019/03.cpp @@ -66,10 +66,8 @@ auto Record ( } // namespace -auto main(int argc, char** argv) -> int { - auto in_ptr = aocpp::Startup(argc, argv); - auto & in = *in_ptr; - +auto Main(std::istream & in) -> void +{ std::string line; std::getline(in, line); auto wire0 = BuildLine(line); diff --git a/2019/04.cpp b/2019/04.cpp index d6ade1a..220e642 100644 --- a/2019/04.cpp +++ b/2019/04.cpp @@ -43,8 +43,9 @@ auto Valid2(std::string const& str) { } // namespace -auto main(int argc, char** argv) -> int { - auto [lo,hi] = Parse(*aocpp::Startup(argc, argv)); +auto Main(std::istream & in) -> void +{ + auto const [lo,hi] = Parse(in); std::int64_t part1 = 0; std::int64_t part2 = 0; diff --git a/2019/05.cpp b/2019/05.cpp index 62f9b40..982f775 100644 --- a/2019/05.cpp +++ b/2019/05.cpp @@ -17,8 +17,9 @@ auto Compute(Machine machine, ValueType d) -> ValueType { } // namespace -auto main(int argc, char** argv) -> int { - auto machine = Machine{ParseStream(*aocpp::Startup(argc, argv))}; +auto Main(std::istream & in) -> 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; } diff --git a/2019/06.cpp b/2019/06.cpp index 0830e11..1b4c0b6 100644 --- a/2019/06.cpp +++ b/2019/06.cpp @@ -88,8 +88,9 @@ TEST_SUITE("documented examples") { } } -auto main(int argc, char** argv) -> int { - auto parents = Parse(*aocpp::Startup(argc, argv)); +auto Main(std::istream & in) -> void +{ + auto const parents {Parse(in)}; std::cout << "Part 1: " << Part1(parents) << std::endl; std::cout << "Part 2: " << Part2(parents) << std::endl; } diff --git a/2019/07.cpp b/2019/07.cpp index 1b5182d..8f9d5d7 100644 --- a/2019/07.cpp +++ b/2019/07.cpp @@ -85,8 +85,9 @@ TEST_SUITE("documented examples") { } } -auto main(int argc, char** argv) -> int { - auto machine = Machine{ParseStream(*aocpp::Startup(argc, argv))}; +auto Main(std::istream & in) -> void +{ + auto machine = Machine{ParseStream(in)}; std::cout << "Part 1: " << Part1(machine) << std::endl; std::cout << "Part 2: " << Part2(std::move(machine)) << std::endl; } diff --git a/2019/08.cpp b/2019/08.cpp index 4a8974d..c8dda9e 100644 --- a/2019/08.cpp +++ b/2019/08.cpp @@ -56,9 +56,10 @@ auto Draw(std::string const& picture) { } // namespace -auto main(int argc, char** argv) -> int { +auto Main(std::istream & in) -> void +{ std::string line; - std::getline(*aocpp::Startup(argc, argv), line); + std::getline(in, line); std::cout << "Part 1: " << Part1(line) << std::endl; Draw(Flatten(line)); } diff --git a/2019/09.cpp b/2019/09.cpp index 96c7dcc..c9520f9 100644 --- a/2019/09.cpp +++ b/2019/09.cpp @@ -29,8 +29,9 @@ TEST_SUITE("documented examples") { } } -auto main(int argc, char** argv) -> int { - auto machine = Machine{ParseStream(*aocpp::Startup(argc, argv))}; +auto Main(std::istream & in) -> 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; } diff --git a/2019/10.cpp b/2019/10.cpp index 0ca9e25..007a04d 100644 --- a/2019/10.cpp +++ b/2019/10.cpp @@ -208,9 +208,10 @@ TEST_SUITE("documented examples") { } } -auto main(int argc, char** argv) -> int { - auto grid = Grid::Parse(*Startup(argc, argv)); - auto [part1, base] = Part1(grid); +auto Main(std::istream & in) -> 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; } diff --git a/2019/11.cpp b/2019/11.cpp index 5b8740b..fe948fe 100644 --- a/2019/11.cpp +++ b/2019/11.cpp @@ -37,8 +37,9 @@ auto Compute(Machine machine, ValueType start) } // namespace -auto main(int argc, char** argv) -> int { - auto machine = Machine{ParseStream(*aocpp::Startup(argc, argv))}; +auto Main(std::istream & in) -> 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)); } diff --git a/2019/12.cpp b/2019/12.cpp index 685c832..5df8a95 100644 --- a/2019/12.cpp +++ b/2019/12.cpp @@ -93,10 +93,11 @@ auto Part2(std::array, 3> const& ps) { } // namespace -auto main(int argc, char** argv) -> int { - auto ps = Parse(*aocpp::Startup(argc, argv)); - auto part2 = Part2(ps); - auto part1 = Part1(std::move(ps), 1000); +auto Main(std::istream & in) -> 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; diff --git a/2019/13.cpp b/2019/13.cpp index 2a3a5b9..03de0fd 100644 --- a/2019/13.cpp +++ b/2019/13.cpp @@ -59,8 +59,9 @@ auto Compute2(Machine machine) { } // namespace -auto main(int argc, char** argv) -> int { - auto machine = Machine{ParseStream(*aocpp::Startup(argc, argv))}; +auto Main(std::istream & in) -> void +{ + auto machine = Machine{ParseStream(in)}; std::cout << "Part 1: " << Compute1(machine) << std::endl; std::cout << "Part 2: " << Compute2(std::move(machine)) << std::endl; } diff --git a/2019/14.cpp b/2019/14.cpp index ac450f0..cf5640c 100644 --- a/2019/14.cpp +++ b/2019/14.cpp @@ -228,11 +228,12 @@ TEST_SUITE("documented examples") { } } -auto main(int argc, char** argv) -> int { - auto recipes = Parse(*aocpp::Startup(argc, argv)); - auto machine = Machine(recipes); - auto part1 = machine(1); - auto part2 = ComputeFuel(machine, 1'000'000'000'000); +auto Main(std::istream & in) -> 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; } diff --git a/2019/15.cpp b/2019/15.cpp index d4a3b63..5c5929c 100644 --- a/2019/15.cpp +++ b/2019/15.cpp @@ -92,8 +92,9 @@ auto Compute(std::map world) -> std::pair { } // namespace -auto main(int argc, char** argv) -> int { - auto [p1,p2] = Compute(Explore(Machine{ParseStream(*aocpp::Startup(argc, argv))})); +auto Main(std::istream & in) -> void +{ + auto const [p1,p2] = Compute(Explore(Machine{ParseStream(in)})); std::cout << "Part 1: " << p1 << std::endl; std::cout << "Part 2: " << p2 << std::endl; } diff --git a/2019/16.cpp b/2019/16.cpp index 61e3c6a..397124c 100644 --- a/2019/16.cpp +++ b/2019/16.cpp @@ -118,8 +118,9 @@ TEST_SUITE("documented examples") { } } -auto main(int argc, char** argv) -> int { - auto input = Parse(*aocpp::Startup(argc, argv)); +auto Main(std::istream & in) -> void +{ + auto const input = Parse(in); std::cout << "Part 1: " << Compute(input, 100, 0) << std::endl; std::cout << "Part 2: " << Part2(input) << std::endl; diff --git a/2019/17.cpp b/2019/17.cpp index 5a45333..fc14455 100644 --- a/2019/17.cpp +++ b/2019/17.cpp @@ -213,14 +213,15 @@ auto GatherScore(Machine m, std::string const& program) -> ValueType { } // namespace -auto main(int argc, char** argv) -> int { - auto machine = Machine{ParseStream(*aocpp::Startup(argc, argv))}; - auto grid = GatherOutput(machine); - auto part1 = ScaffoldAlignments(grid); - auto path = ComputePath(grid); - auto program = ComputeProgram(path); +auto Main(std::istream & in) -> 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; - auto part2 = GatherScore(std::move(machine), program); + auto const part2 = GatherScore(std::move(machine), program); std::cout << "Part 2: " << part2 << std::endl; } diff --git a/2019/18.cpp b/2019/18.cpp index c2dcf86..0a62af0 100644 --- a/2019/18.cpp +++ b/2019/18.cpp @@ -160,8 +160,9 @@ auto Part2(Grid & grid, Features & features) { } // namespace -auto main(int argc, char** argv) -> int { - auto grid = Grid::Parse(*Startup(argc, argv)); +auto Main(std::istream & in) -> void +{ + auto grid = Grid::Parse(in); auto features = FindFeatures(grid); auto distances = FindDistances(grid, features); std::cout << "Part 1: " << SolveMaze(distances, "@") << std::endl; diff --git a/2019/19.cpp b/2019/19.cpp index b5e8f0f..a9a6b8c 100644 --- a/2019/19.cpp +++ b/2019/19.cpp @@ -45,8 +45,9 @@ auto Part2(Scanner const& scanner) { } // namespace -auto main(int argc, char** argv) -> int { - auto scanner = Scanner{Machine{ParseStream(*aocpp::Startup(argc, argv))}}; +auto Main(std::istream & in) -> void +{ + auto const scanner = Scanner{Machine{ParseStream(in)}}; std::cout << "Part 1: " << Part1(scanner) << std::endl; std::cout << "Part 2: " << Part2(scanner) << std::endl; } diff --git a/2019/20.cpp b/2019/20.cpp index a1d33d3..ed64530 100644 --- a/2019/20.cpp +++ b/2019/20.cpp @@ -275,10 +275,11 @@ TEST_SUITE("2019-20 examples") { } -auto main(int argc, char** argv) -> int { - auto map = Grid::Parse(*Startup(argc, argv)); - auto portals = FindPortals(map); - auto distances = FindDistances(map, portals); +auto Main(std::istream & in) -> 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; diff --git a/2019/21.cpp b/2019/21.cpp index af00136..a52c5e9 100644 --- a/2019/21.cpp +++ b/2019/21.cpp @@ -262,8 +262,9 @@ auto Compute( } // namespace -auto main(int argc, char** argv) -> int { - Machine machine {ParseStream(*aocpp::Startup(argc, argv))}; +auto Main(std::istream & in) -> void +{ + Machine machine {ParseStream(in)}; Compute(machine, 4, { "#####.###########", diff --git a/2019/22.cpp b/2019/22.cpp index f0a1f94..e680250 100644 --- a/2019/22.cpp +++ b/2019/22.cpp @@ -114,13 +114,15 @@ auto Many(Shuffle shuffle, unsigned long n) -> Shuffle { } // namespace -auto main(int argc, char** argv) -> int { - auto instructions = Parse(*Startup(argc, argv)); +auto Main(std::istream & in) -> void +{ + auto const instructions {Parse(in)}; - auto shuffle1 = FollowInstructions<10007>(instructions); + auto const shuffle1 {FollowInstructions<10007>(instructions)}; std::cout << "Part 1: " << shuffle1(2019) << std::endl; - auto shuffle2 = FollowInstructions<119315717514047>(instructions); + auto shuffle2 {FollowInstructions<119315717514047>(instructions)}; shuffle2 = Many(shuffle2, 101741582076661); - std::cout << "Part 2: " << shuffle2.inverse()(2020) << std::endl; + shuffle2 = shuffle2.inverse(); + std::cout << "Part 2: " << shuffle2(2020) << std::endl; } diff --git a/2019/23.cpp b/2019/23.cpp index e4e272d..9b90ea6 100644 --- a/2019/23.cpp +++ b/2019/23.cpp @@ -55,8 +55,9 @@ auto Interact(Ethernet & ethernet, Machine & m, std::optional p) -> voi } // namespace -auto main(int const argc, char** const argv) -> int { - auto machines = BuildNetwork(Machine{ParseStream(*aocpp::Startup(argc, argv))}); +auto Main(std::istream & in) -> void +{ + auto machines = BuildNetwork(Machine{ParseStream(in)}); auto ethernet = Ethernet{}; std::optional part1; diff --git a/2019/24.cpp b/2019/24.cpp index 70156cb..f20aedc 100644 --- a/2019/24.cpp +++ b/2019/24.cpp @@ -135,8 +135,9 @@ TEST_SUITE("documented examples") { } } -auto main(int argc, char** argv) -> int { - auto const bugs = FindBugs(Grid::Parse(*Startup(argc, argv))); +auto Main(std::istream & in) -> 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; } diff --git a/2019/25.cpp b/2019/25.cpp index e18cacd..06c2ccf 100644 --- a/2019/25.cpp +++ b/2019/25.cpp @@ -58,7 +58,8 @@ auto Search(std::string & script) } // namespace -auto main(int argc, char** argv) -> int { +auto Main(std::istream & in) -> void +{ std::string script = "north\n" "take sand\n" "north\n" "take space heater\n" @@ -76,5 +77,5 @@ auto main(int argc, char** argv) -> int { Search(script); - RunWithIO(Machine{ParseStream(*aocpp::Startup(argc, argv))}, script); + RunWithIO(Machine{ParseStream(in)}, script); } diff --git a/2020/01.cpp b/2020/01.cpp index dfc9dac..92c8d9b 100644 --- a/2020/01.cpp +++ b/2020/01.cpp @@ -19,12 +19,12 @@ auto Parse(std::istream & in) -> std::vector while (in >> x) { result.push_back(x); } + std::sort(result.begin(), result.end()); return result; } -auto Part1(std::vector entries) { +auto Part1(std::vector const& entries) { std::bitset<2020> numbers; - std::sort(entries.begin(), entries.end()); for (auto const i : entries) { if (i >= 2020) { break; @@ -39,9 +39,8 @@ auto Part1(std::vector entries) { throw std::runtime_error{"no part 1 solution"}; } -auto Part2(std::vector entries) { +auto Part2(std::vector const& entries) { std::bitset<2020> numbers; - std::sort(entries.begin(), entries.end()); for (auto const i : entries) { if (i >= 2020) { break; } if (i < 2020) { numbers.set(i); } @@ -79,8 +78,9 @@ TEST_CASE("part 2") { } -auto main(int argc, char** argv) -> int { - auto entries = Parse(aocpp::Startup(argc, argv)); +auto Main(std::istream & in) -> void +{ + auto const entries {Parse(in)}; std::cout << "Part 1: " << Part1(entries) << std::endl; std::cout << "Part 2: " << Part2(entries) << std::endl; } diff --git a/2020/02.cpp b/2020/02.cpp index d25aa90..8ea8c59 100644 --- a/2020/02.cpp +++ b/2020/02.cpp @@ -56,10 +56,8 @@ TEST_CASE("part 2") { } -auto main(int argc, char** argv) -> int { - auto const in_ptr = aocpp::Startup(argc, argv); - auto & in = *in_ptr; - +auto Main(std::istream & in) -> void +{ std::uint64_t part1{}, part2{}; std::string line; diff --git a/2020/03.cpp b/2020/03.cpp index fd4e005..2c943cf 100644 --- a/2020/03.cpp +++ b/2020/03.cpp @@ -76,8 +76,9 @@ TEST_CASE("part 2") { } -auto main(int argc, char** argv) -> int { - auto grid = Grid::Parse(*Startup(argc, argv)); +auto Main(std::istream & in) -> void +{ + auto const grid {Grid::Parse(in)}; std::cout << "Part 1: " << Part1(grid) << std::endl; std::cout << "Part 2: " << Part2(grid) << std::endl; } diff --git a/2020/10.cpp b/2020/10.cpp index 05e85f7..fdffed6 100644 --- a/2020/10.cpp +++ b/2020/10.cpp @@ -75,8 +75,9 @@ TEST_CASE("part 2") { } -auto main(int argc, char** argv) -> int { - auto adapters = Parse(*aocpp::Startup(argc, argv)); +auto Main(std::istream & in) -> void +{ + auto const adapters {Parse(in)}; std::cout << "Part 1: " << Part1(adapters) << std::endl; std::cout << "Part 2: " << Part2(adapters) << std::endl; } diff --git a/2020/16.cpp b/2020/16.cpp index 7839184..033024d 100644 --- a/2020/16.cpp +++ b/2020/16.cpp @@ -180,12 +180,13 @@ TEST_SUITE("documented examples") { }; auto input = Parse(in); - REQUIRE(Part1(input) == 71); + CHECK(Part1(input) == 71); } } -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; } diff --git a/2020/18.cpp b/2020/18.cpp index 98b94f2..610bbcc 100644 --- a/2020/18.cpp +++ b/2020/18.cpp @@ -140,10 +140,8 @@ TEST_CASE("errors") { } -auto main(int argc, char** argv) -> int { - auto const in_ptr = aocpp::Startup(argc, argv); - auto & in = *in_ptr; - +auto Main(std::istream & in) -> void +{ std::int64_t part1 = 0; std::int64_t part2 = 0; diff --git a/2020/21.cpp b/2020/21.cpp index 79edc15..a39e50d 100644 --- a/2020/21.cpp +++ b/2020/21.cpp @@ -178,8 +178,9 @@ TEST_CASE("part 2") { } -auto main(int argc, char** argv) -> int { - auto const input = Parse(*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; } diff --git a/2020/CMakeLists.txt b/2020/CMakeLists.txt index 08cfc13..0d2aa00 100644 --- a/2020/CMakeLists.txt +++ b/2020/CMakeLists.txt @@ -1,3 +1,6 @@ +add_executable(2020_01 01.cpp) +target_link_libraries(2020_01 aocpp) + add_executable(2020_02 02.cpp) target_link_libraries(2020_02 aocpp) @@ -14,4 +17,4 @@ add_executable(2020_18 18.cpp) target_link_libraries(2020_18 aocpp) add_executable(2020_21 21.cpp) -target_link_libraries(2020_21 aocpp dlx) \ No newline at end of file +target_link_libraries(2020_21 aocpp dlx) diff --git a/2022/01.cpp b/2022/01.cpp index 610d7e8..83db33b 100644 --- a/2022/01.cpp +++ b/2022/01.cpp @@ -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; } diff --git a/2022/02.cpp b/2022/02.cpp index 75bc49e..e2ac5a9 100644 --- a/2022/02.cpp +++ b/2022/02.cpp @@ -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; } diff --git a/2022/03.cpp b/2022/03.cpp index 37007a1..8da471c 100644 --- a/2022/03.cpp +++ b/2022/03.cpp @@ -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; } diff --git a/2022/04.cpp b/2022/04.cpp index 2d93bae..cac7e30 100644 --- a/2022/04.cpp +++ b/2022/04.cpp @@ -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; } diff --git a/2022/06.cpp b/2022/06.cpp index 1bde1cb..a27d981 100644 --- a/2022/06.cpp +++ b/2022/06.cpp @@ -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; } diff --git a/2022/08.cpp b/2022/08.cpp index 941f4d2..b477d2d 100644 --- a/2022/08.cpp +++ b/2022/08.cpp @@ -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; } diff --git a/2022/09.cpp b/2022/09.cpp index c044bb5..9d9d058 100644 --- a/2022/09.cpp +++ b/2022/09.cpp @@ -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; } diff --git a/2022/10.cpp b/2022/10.cpp index cd105eb..489d75f 100644 --- a/2022/10.cpp +++ b/2022/10.cpp @@ -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"); } diff --git a/2022/11.cpp b/2022/11.cpp index 93bb11e..2c28202 100644 --- a/2022/11.cpp +++ b/2022/11.cpp @@ -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; } diff --git a/2022/12.cpp b/2022/12.cpp index f0d9993..6dde7f0 100644 --- a/2022/12.cpp +++ b/2022/12.cpp @@ -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; } diff --git a/2022/13.cpp b/2022/13.cpp index 0ca486c..ae2c1f1 100644 --- a/2022/13.cpp +++ b/2022/13.cpp @@ -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; diff --git a/2022/16.cpp b/2022/16.cpp index 408a48d..e5e9f97 100644 --- a/2022/16.cpp +++ b/2022/16.cpp @@ -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); diff --git a/2022/18.cpp b/2022/18.cpp index ea046c3..3834643 100644 --- a/2022/18.cpp +++ b/2022/18.cpp @@ -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; } diff --git a/2022/20.cpp b/2022/20.cpp index 8c0f635..a004263 100644 --- a/2022/20.cpp +++ b/2022/20.cpp @@ -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; } diff --git a/2022/25.cpp b/2022/25.cpp index f508a19..0e7bedc 100644 --- a/2022/25.cpp +++ b/2022/25.cpp @@ -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; } diff --git a/lib/include/aocpp/Startup.hpp b/lib/include/aocpp/Startup.hpp index fb5208b..d84305c 100644 --- a/lib/include/aocpp/Startup.hpp +++ b/lib/include/aocpp/Startup.hpp @@ -17,4 +17,6 @@ auto Startup(int argc, char ** argv) -> std::unique_ptr void; + #endif diff --git a/lib/src/Startup.cpp b/lib/src/Startup.cpp index 51b9570..590103b 100644 --- a/lib/src/Startup.cpp +++ b/lib/src/Startup.cpp @@ -29,3 +29,13 @@ auto Startup(int argc, char ** argv) -> std::unique_ptr int +{ + try { + Main(*aocpp::Startup(argc, argv)); + } catch (std::exception const& e) { + std::cerr << "Program failed: " << e.what() << std::endl; + return 1; + } +}