-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday22-part2.cpp
More file actions
39 lines (31 loc) · 788 Bytes
/
day22-part2.cpp
File metadata and controls
39 lines (31 loc) · 788 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
#include "loadSteps.hpp"
#include "Modular.hpp"
int main() {
constexpr uint64_t deckSize = 119315717514047;
constexpr uint64_t iterations = 101741582076661;
constexpr uint64_t value = 2020;
auto steps = loadSteps(std::cin);
Modular<deckSize> mul(1);
Modular<deckSize> add(0);
for (auto it = steps.rbegin(); it != steps.rend(); ++it) {
if(it->first == 'c') {
add += it->second;
} else if(it->first == 'd') {
mul /= it->second;
add /= it->second;
} else if(it->first == 'r') {
mul = -mul;
add = -add - 1;
}
}
if (mul.getValue() != 1) {
add *= (1 - (mul ^ iterations)) / (1 - mul);
} else {
add *= iterations;
}
mul ^= iterations;
auto result = mul * value + add;
std::cout << result.getValue() << std::endl;
return 0;
}