diff --git a/2025/2.txt b/2025/2.txt new file mode 100644 index 0000000..a3f22ef --- /dev/null +++ b/2025/2.txt @@ -0,0 +1 @@ +11-22,95-115,998-1012,1188511880-1188511890,222220-222224,1698522-1698528,446443-446449,38593856-38593862,565653-565659,824824821-824824827,2121212118-2121212124 diff --git a/2025/aoc b/2025/aoc index 8b02657..9017751 100755 Binary files a/2025/aoc and b/2025/aoc differ diff --git a/2025/aoc.cpp b/2025/aoc.cpp index 99f2cd4..31fee50 100644 --- a/2025/aoc.cpp +++ b/2025/aoc.cpp @@ -3,6 +3,7 @@ #include "aoc.hpp" #include "day1.hpp" +#include "day2.hpp" int main(int argc, char** argv) { diff --git a/2025/aoc.hpp b/2025/aoc.hpp index eca63d2..7c339eb 100644 --- a/2025/aoc.hpp +++ b/2025/aoc.hpp @@ -12,6 +12,11 @@ struct FileFragment std::string Data; }; +inline std::pair SplitToken(std::string del) +{ + +} + class File { public: diff --git a/2025/day2.hpp b/2025/day2.hpp new file mode 100644 index 0000000..bfd0e00 --- /dev/null +++ b/2025/day2.hpp @@ -0,0 +1,116 @@ +#include "aoc.hpp" + +#include +#include + +class Day02 : public AOCDay +{ +public: + Day02() {} + ~Day02() {} + int Day() override {return 2;} + + int PartOne(File& f) override + { + f.SplitBy(","); + + uint64_t res = 0; + + // Range of ID's (11-22) + for (auto range : f.TokensForLine(0)) + { + int dash = range.Data.find('-', 0); + + uint64_t a = std::stoll(range.Data.substr(0, dash)); + uint64_t b = std::stoll(range.Data.substr(dash + 1)); + + for (uint64_t i = a; i <= b; i++) + { + // Convert number back into string + std::string current = std::to_string(i); + // import 'is-odd' lol + if (current.length() & 1) continue; + + int mid = current.length() / 2; + + uint64_t l = std::stoll(current.substr(0, mid)); + uint64_t r = std::stoll(current.substr(mid)); + + if (l == r) + { + res += i; + } + } + } + + std::cout << "The answer doesn't fit in int : "<< res << std::endl; + return res; + } + + int PartTwo(File& f) override + { + f.SplitBy(","); + + uint64_t res = 0; + + for (auto range : f.TokensForLine(0)) + { + int dash = range.Data.find('-', 0); + + uint64_t a = std::stoll(range.Data.substr(0, dash)); + uint64_t b = std::stoll(range.Data.substr(dash + 1)); + + for (uint64_t i = a; i <= b; i++) + { + std::string current = std::to_string(i); + int n = current.length(); + + bool invalid = false; + + // Try every possible substring start (i) + for (int start = 0; start < n && !invalid; start++) + { + std::string accum; + + // Build accum char-by-char + for (int end = start; end < n && !invalid; end++) + { + accum.push_back(current[end]); + + int len = accum.length(); + int remaining = n - start; + + // Now check if repeats match + bool matches = true; + + for (int rep = 0; rep < remaining / len; rep++) + { + if (current.compare(start + rep * len, len, accum) != 0) + { + matches = false; + break; + } + } + + // Must be at least two repeats + if (matches && remaining / len >= 2) + { + invalid = true; + break; + } + } + } + + if (invalid) + res += i; + } + } + + + std::cout << "The answer doesn't fit in int : "<< res << std::endl; + return res; + } +}; + +ADD_AOC_DAY(Day02); +