From 24ae9b5069079fa12b5a4a9c6803b3c559da3117 Mon Sep 17 00:00:00 2001 From: Thraix Date: Sun, 30 Nov 2025 16:31:38 +0100 Subject: [PATCH] Setup AoC for 2025 --- fetch.sh | 14 +++++++-- src/2025/Day01.cpp | 36 +++++++++++++++++++++++ src/2025/Day02.cpp | 36 +++++++++++++++++++++++ src/2025/Day03.cpp | 36 +++++++++++++++++++++++ src/2025/Day04.cpp | 36 +++++++++++++++++++++++ src/2025/Day05.cpp | 36 +++++++++++++++++++++++ src/2025/Day06.cpp | 36 +++++++++++++++++++++++ src/2025/Day07.cpp | 36 +++++++++++++++++++++++ src/2025/Day08.cpp | 36 +++++++++++++++++++++++ src/2025/Day09.cpp | 36 +++++++++++++++++++++++ src/2025/Day10.cpp | 36 +++++++++++++++++++++++ src/2025/Day11.cpp | 36 +++++++++++++++++++++++ src/2025/Day12.cpp | 36 +++++++++++++++++++++++ src/common/main.cpp | 69 +++++++++++++++++++++++++++++++++++++++++---- 14 files changed, 507 insertions(+), 8 deletions(-) create mode 100644 src/2025/Day01.cpp create mode 100644 src/2025/Day02.cpp create mode 100644 src/2025/Day03.cpp create mode 100644 src/2025/Day04.cpp create mode 100644 src/2025/Day05.cpp create mode 100644 src/2025/Day06.cpp create mode 100644 src/2025/Day07.cpp create mode 100644 src/2025/Day08.cpp create mode 100644 src/2025/Day09.cpp create mode 100644 src/2025/Day10.cpp create mode 100644 src/2025/Day11.cpp create mode 100644 src/2025/Day12.cpp diff --git a/fetch.sh b/fetch.sh index dda8c13..c9cedfb 100755 --- a/fetch.sh +++ b/fetch.sh @@ -14,8 +14,16 @@ for item in $list; do if [ ! -e $dir ]; then webitem=$(echo $day | sed 's/^0//g') echo "Fetching $dir" - mkdir -p "res/$year/day$day/" - touch "res/$year/day$day/test_input.txt" - curl -s --cookie cookies.txt https://adventofcode.com/$year/day/$webitem/input >$dir + tmp_file=$(mktemp) + HTTP_CODE=$(curl -s -w "%{http_code}" -o "$tmp_file" --cookie cookies.txt https://adventofcode.com/$year/day/$webitem/input) + if [ "$HTTP_CODE" -eq 200 ]; then + mkdir -p "res/$year/day$day/" + touch "res/$year/day$day/test_input.txt" + mv "$tmp_file" $dir + else + echo "Failed to fetch with status: $HTTP_CODE" + rm "$tmp_file" + exit 1 + fi fi done diff --git a/src/2025/Day01.cpp b/src/2025/Day01.cpp new file mode 100644 index 0000000..52b0b28 --- /dev/null +++ b/src/2025/Day01.cpp @@ -0,0 +1,36 @@ +#include "common/aoc.h" + +namespace y2025::day01 +{ + using InputType = std::vector; + REGISTER_DAY(2025, Day01, InputType, int); + + REGISTER_TEST_EXAMPLE(2025, Day01, ExampleInput, 1, 0); + REGISTER_TEST(2025, Day01, Input, 1, 0); + REGISTER_TEST_EXAMPLE(2025, Day01, ExampleInput, 2, 0); + REGISTER_TEST(2025, Day01, Input, 2, 0); + + READ_INPUT(input) + { + std::vector vec; + std::string str; + while (std::getline(input, str)) + { + std::stringstream ss{str}; + int n; + ss >> n; + vec.emplace_back(n); + } + return vec; + } + + OUTPUT1(input) + { + return 0; + } + + OUTPUT2(input) + { + return 0; + } +} diff --git a/src/2025/Day02.cpp b/src/2025/Day02.cpp new file mode 100644 index 0000000..e18d0c5 --- /dev/null +++ b/src/2025/Day02.cpp @@ -0,0 +1,36 @@ +#include "common/aoc.h" + +namespace y2025::day02 +{ + using InputType = std::vector; + REGISTER_DAY(2025, Day02, InputType, int); + + REGISTER_TEST_EXAMPLE(2025, Day02, ExampleInput, 1, 0); + REGISTER_TEST(2025, Day02, Input, 1, 0); + REGISTER_TEST_EXAMPLE(2025, Day02, ExampleInput, 2, 0); + REGISTER_TEST(2025, Day02, Input, 2, 0); + + READ_INPUT(input) + { + std::vector vec; + std::string str; + while (std::getline(input, str)) + { + std::stringstream ss{str}; + int n; + ss >> n; + vec.emplace_back(n); + } + return vec; + } + + OUTPUT1(input) + { + return 0; + } + + OUTPUT2(input) + { + return 0; + } +} diff --git a/src/2025/Day03.cpp b/src/2025/Day03.cpp new file mode 100644 index 0000000..bf2cc73 --- /dev/null +++ b/src/2025/Day03.cpp @@ -0,0 +1,36 @@ +#include "common/aoc.h" + +namespace y2025::day03 +{ + using InputType = std::vector; + REGISTER_DAY(2025, Day03, InputType, int); + + REGISTER_TEST_EXAMPLE(2025, Day03, ExampleInput, 1, 0); + REGISTER_TEST(2025, Day03, Input, 1, 0); + REGISTER_TEST_EXAMPLE(2025, Day03, ExampleInput, 2, 0); + REGISTER_TEST(2025, Day03, Input, 2, 0); + + READ_INPUT(input) + { + std::vector vec; + std::string str; + while (std::getline(input, str)) + { + std::stringstream ss{str}; + int n; + ss >> n; + vec.emplace_back(n); + } + return vec; + } + + OUTPUT1(input) + { + return 0; + } + + OUTPUT2(input) + { + return 0; + } +} diff --git a/src/2025/Day04.cpp b/src/2025/Day04.cpp new file mode 100644 index 0000000..71cf8fa --- /dev/null +++ b/src/2025/Day04.cpp @@ -0,0 +1,36 @@ +#include "common/aoc.h" + +namespace y2025::day04 +{ + using InputType = std::vector; + REGISTER_DAY(2025, Day04, InputType, int); + + REGISTER_TEST_EXAMPLE(2025, Day04, ExampleInput, 1, 0); + REGISTER_TEST(2025, Day04, Input, 1, 0); + REGISTER_TEST_EXAMPLE(2025, Day04, ExampleInput, 2, 0); + REGISTER_TEST(2025, Day04, Input, 2, 0); + + READ_INPUT(input) + { + std::vector vec; + std::string str; + while (std::getline(input, str)) + { + std::stringstream ss{str}; + int n; + ss >> n; + vec.emplace_back(n); + } + return vec; + } + + OUTPUT1(input) + { + return 0; + } + + OUTPUT2(input) + { + return 0; + } +} diff --git a/src/2025/Day05.cpp b/src/2025/Day05.cpp new file mode 100644 index 0000000..986445b --- /dev/null +++ b/src/2025/Day05.cpp @@ -0,0 +1,36 @@ +#include "common/aoc.h" + +namespace y2025::day05 +{ + using InputType = std::vector; + REGISTER_DAY(2025, Day05, InputType, int); + + REGISTER_TEST_EXAMPLE(2025, Day05, ExampleInput, 1, 0); + REGISTER_TEST(2025, Day05, Input, 1, 0); + REGISTER_TEST_EXAMPLE(2025, Day05, ExampleInput, 2, 0); + REGISTER_TEST(2025, Day05, Input, 2, 0); + + READ_INPUT(input) + { + std::vector vec; + std::string str; + while (std::getline(input, str)) + { + std::stringstream ss{str}; + int n; + ss >> n; + vec.emplace_back(n); + } + return vec; + } + + OUTPUT1(input) + { + return 0; + } + + OUTPUT2(input) + { + return 0; + } +} diff --git a/src/2025/Day06.cpp b/src/2025/Day06.cpp new file mode 100644 index 0000000..3d7c1f6 --- /dev/null +++ b/src/2025/Day06.cpp @@ -0,0 +1,36 @@ +#include "common/aoc.h" + +namespace y2025::day06 +{ + using InputType = std::vector; + REGISTER_DAY(2025, Day06, InputType, int); + + REGISTER_TEST_EXAMPLE(2025, Day06, ExampleInput, 1, 0); + REGISTER_TEST(2025, Day06, Input, 1, 0); + REGISTER_TEST_EXAMPLE(2025, Day06, ExampleInput, 2, 0); + REGISTER_TEST(2025, Day06, Input, 2, 0); + + READ_INPUT(input) + { + std::vector vec; + std::string str; + while (std::getline(input, str)) + { + std::stringstream ss{str}; + int n; + ss >> n; + vec.emplace_back(n); + } + return vec; + } + + OUTPUT1(input) + { + return 0; + } + + OUTPUT2(input) + { + return 0; + } +} diff --git a/src/2025/Day07.cpp b/src/2025/Day07.cpp new file mode 100644 index 0000000..5b96394 --- /dev/null +++ b/src/2025/Day07.cpp @@ -0,0 +1,36 @@ +#include "common/aoc.h" + +namespace y2025::day07 +{ + using InputType = std::vector; + REGISTER_DAY(2025, Day07, InputType, int); + + REGISTER_TEST_EXAMPLE(2025, Day07, ExampleInput, 1, 0); + REGISTER_TEST(2025, Day07, Input, 1, 0); + REGISTER_TEST_EXAMPLE(2025, Day07, ExampleInput, 2, 0); + REGISTER_TEST(2025, Day07, Input, 2, 0); + + READ_INPUT(input) + { + std::vector vec; + std::string str; + while (std::getline(input, str)) + { + std::stringstream ss{str}; + int n; + ss >> n; + vec.emplace_back(n); + } + return vec; + } + + OUTPUT1(input) + { + return 0; + } + + OUTPUT2(input) + { + return 0; + } +} diff --git a/src/2025/Day08.cpp b/src/2025/Day08.cpp new file mode 100644 index 0000000..d49fa2d --- /dev/null +++ b/src/2025/Day08.cpp @@ -0,0 +1,36 @@ +#include "common/aoc.h" + +namespace y2025::day08 +{ + using InputType = std::vector; + REGISTER_DAY(2025, Day08, InputType, int); + + REGISTER_TEST_EXAMPLE(2025, Day08, ExampleInput, 1, 0); + REGISTER_TEST(2025, Day08, Input, 1, 0); + REGISTER_TEST_EXAMPLE(2025, Day08, ExampleInput, 2, 0); + REGISTER_TEST(2025, Day08, Input, 2, 0); + + READ_INPUT(input) + { + std::vector vec; + std::string str; + while (std::getline(input, str)) + { + std::stringstream ss{str}; + int n; + ss >> n; + vec.emplace_back(n); + } + return vec; + } + + OUTPUT1(input) + { + return 0; + } + + OUTPUT2(input) + { + return 0; + } +} diff --git a/src/2025/Day09.cpp b/src/2025/Day09.cpp new file mode 100644 index 0000000..b2b7ef2 --- /dev/null +++ b/src/2025/Day09.cpp @@ -0,0 +1,36 @@ +#include "common/aoc.h" + +namespace y2025::day09 +{ + using InputType = std::vector; + REGISTER_DAY(2025, Day09, InputType, int); + + REGISTER_TEST_EXAMPLE(2025, Day09, ExampleInput, 1, 0); + REGISTER_TEST(2025, Day09, Input, 1, 0); + REGISTER_TEST_EXAMPLE(2025, Day09, ExampleInput, 2, 0); + REGISTER_TEST(2025, Day09, Input, 2, 0); + + READ_INPUT(input) + { + std::vector vec; + std::string str; + while (std::getline(input, str)) + { + std::stringstream ss{str}; + int n; + ss >> n; + vec.emplace_back(n); + } + return vec; + } + + OUTPUT1(input) + { + return 0; + } + + OUTPUT2(input) + { + return 0; + } +} diff --git a/src/2025/Day10.cpp b/src/2025/Day10.cpp new file mode 100644 index 0000000..3e7a6db --- /dev/null +++ b/src/2025/Day10.cpp @@ -0,0 +1,36 @@ +#include "common/aoc.h" + +namespace y2025::day10 +{ + using InputType = std::vector; + REGISTER_DAY(2025, Day10, InputType, int); + + REGISTER_TEST_EXAMPLE(2025, Day10, ExampleInput, 1, 0); + REGISTER_TEST(2025, Day10, Input, 1, 0); + REGISTER_TEST_EXAMPLE(2025, Day10, ExampleInput, 2, 0); + REGISTER_TEST(2025, Day10, Input, 2, 0); + + READ_INPUT(input) + { + std::vector vec; + std::string str; + while (std::getline(input, str)) + { + std::stringstream ss{str}; + int n; + ss >> n; + vec.emplace_back(n); + } + return vec; + } + + OUTPUT1(input) + { + return 0; + } + + OUTPUT2(input) + { + return 0; + } +} diff --git a/src/2025/Day11.cpp b/src/2025/Day11.cpp new file mode 100644 index 0000000..61606d3 --- /dev/null +++ b/src/2025/Day11.cpp @@ -0,0 +1,36 @@ +#include "common/aoc.h" + +namespace y2025::day11 +{ + using InputType = std::vector; + REGISTER_DAY(2025, Day11, InputType, int); + + REGISTER_TEST_EXAMPLE(2025, Day11, ExampleInput, 1, 0); + REGISTER_TEST(2025, Day11, Input, 1, 0); + REGISTER_TEST_EXAMPLE(2025, Day11, ExampleInput, 2, 0); + REGISTER_TEST(2025, Day11, Input, 2, 0); + + READ_INPUT(input) + { + std::vector vec; + std::string str; + while (std::getline(input, str)) + { + std::stringstream ss{str}; + int n; + ss >> n; + vec.emplace_back(n); + } + return vec; + } + + OUTPUT1(input) + { + return 0; + } + + OUTPUT2(input) + { + return 0; + } +} diff --git a/src/2025/Day12.cpp b/src/2025/Day12.cpp new file mode 100644 index 0000000..95c3995 --- /dev/null +++ b/src/2025/Day12.cpp @@ -0,0 +1,36 @@ +#include "common/aoc.h" + +namespace y2025::day12 +{ + using InputType = std::vector; + REGISTER_DAY(2025, Day12, InputType, int); + + REGISTER_TEST_EXAMPLE(2025, Day12, ExampleInput, 1, 0); + REGISTER_TEST(2025, Day12, Input, 1, 0); + REGISTER_TEST_EXAMPLE(2025, Day12, ExampleInput, 2, 0); + REGISTER_TEST(2025, Day12, Input, 2, 0); + + READ_INPUT(input) + { + std::vector vec; + std::string str; + while (std::getline(input, str)) + { + std::stringstream ss{str}; + int n; + ss >> n; + vec.emplace_back(n); + } + return vec; + } + + OUTPUT1(input) + { + return 0; + } + + OUTPUT2(input) + { + return 0; + } +} diff --git a/src/common/main.cpp b/src/common/main.cpp index e905385..0088078 100644 --- a/src/common/main.cpp +++ b/src/common/main.cpp @@ -10,17 +10,72 @@ aoc::Registry* aoc::Registry::GetInstance() return instance; } +struct Args +{ + std::string testRegex{""}; + bool stopIfFailed{false}; + + friend std::ostream& operator<<(std::ostream& os, const Args& args) + { + return os << "regex=" << args.testRegex << "\nstopIfFailed=" << (args.stopIfFailed ? "true" : "false"); + } +}; + +Args ParseArgs(const std::vector& arguments) +{ + Args args; + for (const std::string& argument : arguments) + { + if (Helper::StartsWith(argument, "--stop-if-failed")) + { + args.stopIfFailed = true; + } + else if (Helper::StartsWith(argument, "--filter=")) + { + args.testRegex = std::string(argument).substr(sizeof("--filter=") - 1); + } + else + { + std::cout << "Unknown argument: " << argument << std::endl; + } + } + return args; +} + +std::vector ReadArgs(int argc, char** argv) +{ + std::vector arguments; + for (int i = 1; i < argc; i++) + { + arguments.emplace_back(argv[i]); + } + + if (arguments.empty()) + { + std::ifstream inputStream{"config.txt"}; + if (inputStream.is_open()) + { + std::string str; + while (inputStream >> str) + { + arguments.emplace_back(str); + } + } + } + return arguments; +} + int main(int argc, char** argv) { - std::regex regex{""}; - if (argc > 1) - regex = argv[1]; + Args args = ParseArgs(ReadArgs(argc, argv)); + std::regex regex{args.testRegex}; Timer totalTimer; int passed = 0; int skipped = 0; - for (auto day : aoc::Registry::GetDays()) + bool stopped = false; + for (const auto& day : aoc::Registry::GetDays()) { - if (!std::regex_search(day->GetName(), regex)) + if (!std::regex_search(day->GetName(), regex) || stopped) { skipped++; continue; @@ -42,6 +97,10 @@ int main(int argc, char** argv) { std::cout << TERM_RED << "[=========] " << TERM_CLEAR << std::endl; std::cout << TERM_RED << "[ FAILED ] " << TERM_CLEAR << day->GetName() << std::endl; + if (args.stopIfFailed) + { + stopped = true; + } } std::cout << std::endl; }