Use a common main
This commit is contained in:
parent
542ccc7884
commit
c6264a2a1b
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -9,9 +9,10 @@
|
|||
#include <aocpp/Parsing.hpp>
|
||||
#include <knothash.hpp>
|
||||
|
||||
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<std::uint8_t> lengths1;
|
||||
for (auto && x : aocpp::SplitOn(line, ",")) {
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -40,7 +40,7 @@ auto Caught(std::vector<Scanner> const& scanners) -> std::size_t {
|
|||
return severity;
|
||||
}
|
||||
|
||||
auto Delay(std::vector<Scanner> & scanners) {
|
||||
auto Delay(std::vector<Scanner> 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;
|
||||
std::cout << "Part 2: " << Delay(std::move(input)) << std::endl;
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -93,10 +93,11 @@ auto Part2(std::array<std::vector<Particle>, 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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
11
2019/14.cpp
11
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;
|
||||
}
|
||||
|
|
|
@ -92,8 +92,9 @@ auto Compute(std::map<Coord, ValueType> world) -> std::pair<int, int> {
|
|||
|
||||
} // 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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
15
2019/17.cpp
15
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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
{ "#####.###########",
|
||||
|
|
12
2019/22.cpp
12
2019/22.cpp
|
@ -114,13 +114,15 @@ auto Many(Shuffle<Cards> shuffle, unsigned long n) -> Shuffle<Cards> {
|
|||
|
||||
} // 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;
|
||||
}
|
||||
|
|
|
@ -55,8 +55,9 @@ auto Interact(Ethernet & ethernet, Machine & m, std::optional<Payload> 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<ValueType> part1;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
12
2020/01.cpp
12
2020/01.cpp
|
@ -19,12 +19,12 @@ auto Parse(std::istream & in) -> std::vector<std::int64_t>
|
|||
while (in >> x) {
|
||||
result.push_back(x);
|
||||
}
|
||||
std::sort(result.begin(), result.end());
|
||||
return result;
|
||||
}
|
||||
|
||||
auto Part1(std::vector<std::int64_t> entries) {
|
||||
auto Part1(std::vector<std::int64_t> 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<std::int64_t> entries) {
|
|||
throw std::runtime_error{"no part 1 solution"};
|
||||
}
|
||||
|
||||
auto Part2(std::vector<std::int64_t> entries) {
|
||||
auto Part2(std::vector<std::int64_t> 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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
10
2022/16.cpp
10
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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -17,4 +17,6 @@ auto Startup(int argc, char ** argv) -> std::unique_ptr<std::istream, void(*)(st
|
|||
|
||||
}
|
||||
|
||||
auto Main(std::istream & in) -> void;
|
||||
|
||||
#endif
|
||||
|
|
|
@ -29,3 +29,13 @@ 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));
|
||||
} catch (std::exception const& e) {
|
||||
std::cerr << "Program failed: " << e.what() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user