-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path25.cpp
117 lines (110 loc) · 2.18 KB
/
25.cpp
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <chrono>
#include <iostream>
#include <unordered_map>
enum class State {
A,
B,
C,
D,
E,
F,
};
int main() {
auto tstart = std::chrono::high_resolution_clock::now();
int pt1 = 0;
State state{State::A};
int steps = 12459852;
std::unordered_map<int, bool> lint;
int slot = 0;
for (int i = 0; i < steps; i++) {
switch (state) {
case State::A: {
if (false == lint[slot]) {
lint[slot] = true;
slot++;
state = State::B;
pt1++;
} else {
slot--;
state = State::E;
}
break;
}
case State::B: {
if (false == lint[slot]) {
lint[slot] = true;
slot++;
state = State::C;
pt1++;
} else {
slot++;
state = State::F;
}
break;
}
case State::C: {
if (false == lint[slot]) {
lint[slot] = true;
slot--;
state = State::D;
pt1++;
} else {
lint[slot] = false;
pt1--;
slot++;
state = State::B;
}
break;
}
case State::D: {
if (false == lint[slot]) {
lint[slot] = true;
slot++;
state = State::E;
pt1++;
} else {
lint[slot] = false;
slot--;
state = State::C;
pt1--;
}
break;
}
case State::E: {
if (false == lint[slot]) {
lint[slot] = true;
slot--;
state = State::A;
pt1++;
} else {
lint[slot] = false;
slot++;
state = State::D;
pt1--;
}
break;
}
case State::F: {
if (false == lint[slot]) {
lint[slot] = true;
slot++;
state = State::A;
pt1++;
} else {
slot++;
state = State::C;
}
break;
}
}
}
std::cout << "--- Day 25: The Halting Problem ---\n";
std::cout << "Part 1: " << pt1 << "\n";
auto tstop = std::chrono::high_resolution_clock::now();
auto duration =
std::chrono::duration_cast<std::chrono::microseconds>(tstop - tstart);
std::cout << "Time: " << (static_cast<double>(duration.count()) / 1000.0)
<< " ms"
<< "\n";
return EXIT_SUCCESS;
}