Add solution for 2015 Day 25
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
To continue, please consult the code grid in the manual. Enter the code at row 3, column 4.
|
||||||
|
|||||||
+16
-9
@@ -2,26 +2,33 @@
|
|||||||
|
|
||||||
namespace y2015::day25
|
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_EXAMPLE(2015, Day25, ExampleInput, 1, 7981243);
|
||||||
REGISTER_TEST(2015, Day25, Input, 1, 0);
|
REGISTER_TEST(2015, Day25, Input, 1, 8997277);
|
||||||
REGISTER_TEST_EXAMPLE(2015, Day25, ExampleInput, 2, 0);
|
REGISTER_TEST_EXAMPLE(2015, Day25, ExampleInput, 2, 0);
|
||||||
REGISTER_TEST(2015, Day25, Input, 2, 0);
|
REGISTER_TEST(2015, Day25, Input, 2, 0);
|
||||||
|
|
||||||
READ_INPUT(input)
|
READ_INPUT(input)
|
||||||
{
|
{
|
||||||
std::vector<int> vec;
|
int i1;
|
||||||
std::string str;
|
int i2;
|
||||||
while (getline(input, str))
|
input >> "To continue, please consult the code grid in the manual. Enter the code at row " >> i2 >> ", column " >>
|
||||||
{
|
i1;
|
||||||
|
|
||||||
|
return std::pair{i1, i2};
|
||||||
}
|
}
|
||||||
return vec;
|
|
||||||
|
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)
|
OUTPUT1(input)
|
||||||
{
|
{
|
||||||
return 0;
|
return Helper::FastExponentiation(20151125, 252533, GetPower(input) - 1, 33554393);
|
||||||
}
|
}
|
||||||
|
|
||||||
OUTPUT2(input)
|
OUTPUT2(input)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
template <typename Key, typename Value>
|
template <typename Key, typename Value>
|
||||||
class Graph
|
class Graph
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
@@ -607,6 +609,24 @@ struct Helper
|
|||||||
return currentRes;
|
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
|
// Input - Puzzle input
|
||||||
// Function - bool(int64_t);
|
// Function - bool(int64_t);
|
||||||
// Given index, return whether the index should increase next
|
// Given index, return whether the index should increase next
|
||||||
|
|||||||
@@ -388,7 +388,7 @@ public:
|
|||||||
else if (json.IsInt())
|
else if (json.IsInt())
|
||||||
os << json.GetInt64();
|
os << json.GetInt64();
|
||||||
else if (json.IsBool())
|
else if (json.IsBool())
|
||||||
os << json.GetBool() ? "true" : "false";
|
os << (json.GetBool() ? "true" : "false");
|
||||||
else if (json.IsNull())
|
else if (json.IsNull())
|
||||||
os << "null";
|
os << "null";
|
||||||
return os;
|
return os;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#include "JsonUtil.h"
|
#include "JsonUtil.h"
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
#include "Json.h"
|
#include "Json.h"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user