diff --git a/res/2015/day25/test_input.txt b/res/2015/day25/test_input.txt index e69de29..1b7db61 100644 --- a/res/2015/day25/test_input.txt +++ b/res/2015/day25/test_input.txt @@ -0,0 +1 @@ +To continue, please consult the code grid in the manual. Enter the code at row 3, column 4. diff --git a/src/2015/Day25.cpp b/src/2015/Day25.cpp index 4a7d6b8..d65d724 100644 --- a/src/2015/Day25.cpp +++ b/src/2015/Day25.cpp @@ -2,26 +2,33 @@ namespace y2015::day25 { - REGISTER_DAY(2015, Day25, std::vector, int); + using Pair = std::pair; + REGISTER_DAY(2015, Day25, Pair, int); - REGISTER_TEST_EXAMPLE(2015, Day25, ExampleInput, 1, 0); - REGISTER_TEST(2015, Day25, Input, 1, 0); + REGISTER_TEST_EXAMPLE(2015, Day25, ExampleInput, 1, 7981243); + REGISTER_TEST(2015, Day25, Input, 1, 8997277); REGISTER_TEST_EXAMPLE(2015, Day25, ExampleInput, 2, 0); REGISTER_TEST(2015, Day25, Input, 2, 0); READ_INPUT(input) { - std::vector vec; - std::string str; - while (getline(input, str)) - { - } - return vec; + int i1; + int i2; + input >> "To continue, please consult the code grid in the manual. Enter the code at row " >> i2 >> ", column " >> + i1; + + return std::pair{i1, i2}; + } + + int GetPower(const std::pair& coordinate) + { + return (coordinate.first + coordinate.second - 1) * (coordinate.first + coordinate.second - 1 + 1) / 2 + 1 - + coordinate.second; } OUTPUT1(input) { - return 0; + return Helper::FastExponentiation(20151125, 252533, GetPower(input) - 1, 33554393); } OUTPUT2(input) diff --git a/src/common/lib/Graph.h b/src/common/lib/Graph.h index 79cb8f7..92d1e17 100644 --- a/src/common/lib/Graph.h +++ b/src/common/lib/Graph.h @@ -2,6 +2,7 @@ #include #include +#include template class Graph diff --git a/src/common/lib/Helper.h b/src/common/lib/Helper.h index 0d7cf41..19a529b 100644 --- a/src/common/lib/Helper.h +++ b/src/common/lib/Helper.h @@ -1,5 +1,7 @@ #pragma once +#include + #include #include #include @@ -607,6 +609,24 @@ struct Helper return currentRes; } + static uint64_t FastExponentiation(uint64_t start, uint64_t multiplication, uint64_t power, uint64_t mod) + { + while (power > 0) + { + if (power % 2 == 0) + { + multiplication = (multiplication * multiplication) % mod; + power /= 2; + } + else + { + start = (start * multiplication) % mod; + power--; + } + } + return start; + } + // Input - Puzzle input // Function - bool(int64_t); // Given index, return whether the index should increase next diff --git a/src/common/lib/Json.h b/src/common/lib/Json.h index 569e740..7066d2f 100644 --- a/src/common/lib/Json.h +++ b/src/common/lib/Json.h @@ -388,7 +388,7 @@ public: else if (json.IsInt()) os << json.GetInt64(); else if (json.IsBool()) - os << json.GetBool() ? "true" : "false"; + os << (json.GetBool() ? "true" : "false"); else if (json.IsNull()) os << "null"; return os; diff --git a/src/common/lib/JsonUtil.cpp b/src/common/lib/JsonUtil.cpp index 3c28380..c2408a1 100644 --- a/src/common/lib/JsonUtil.cpp +++ b/src/common/lib/JsonUtil.cpp @@ -1,7 +1,6 @@ #include "JsonUtil.h" #include -#include #include "Json.h"