Add solution for 2015 Day 25

This commit is contained in:
Thraix
2026-08-05 23:41:32 +02:00
parent 4de110a517
commit 9237445a13
6 changed files with 40 additions and 12 deletions
+1
View File
@@ -0,0 +1 @@
To continue, please consult the code grid in the manual. Enter the code at row 3, column 4.
+17 -10
View File
@@ -2,26 +2,33 @@
namespace y2015::day25
{
REGISTER_DAY(2015, Day25, std::vector<int>, int);
using Pair = std::pair<int, int>;
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<int> 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<int, int>& 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)
+1
View File
@@ -2,6 +2,7 @@
#include <map>
#include <set>
#include <vector>
template <typename Key, typename Value>
class Graph
+20
View File
@@ -1,5 +1,7 @@
#pragma once
#include <stdint.h>
#include <algorithm>
#include <array>
#include <functional>
@@ -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
+1 -1
View File
@@ -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;
-1
View File
@@ -1,7 +1,6 @@
#include "JsonUtil.h"
#include <cstring>
#include <utility>
#include "Json.h"