-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpuzzle_25_1.cc
97 lines (85 loc) · 2.07 KB
/
puzzle_25_1.cc
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
#include <iostream>
#include <set>
const int MIDDLE = 12261543;
using Tape = std::set<int>;
Tape tape;
int main()
{
unsigned char state = 'A';
int pos = 0;
for (int i = 0; i < MIDDLE; ++i) {
auto it = tape.find(pos);
switch (state) {
// Begin in state A.
// Perform a diagnostic checksum after 12261543 steps.
case 'A':
if (it == tape.end()) {
tape.insert(pos);
++pos;
state = 'B';
} else {
tape.erase(pos);
--pos;
state = 'C';
}
break;
case 'B':
if (it == tape.end()) {
tape.insert(pos);
--pos;
state = 'A';
} else {
tape.insert(pos);
++pos;
state = 'C';
}
break;
case 'C':
if (it == tape.end()) {
tape.insert(pos);
++pos;
state = 'A';
} else {
tape.erase(pos);
--pos;
state = 'D';
}
break;
case 'D':
if (it == tape.end()) {
tape.insert(pos);
--pos;
state = 'E';
} else {
tape.insert(pos);
--pos;
state = 'C';
}
break;
case 'E':
if (it == tape.end()) {
tape.insert(pos);
++pos;
state = 'F';
} else {
tape.insert(pos);
++pos;
state = 'A';
}
break;
case 'F':
if (it == tape.end()) {
tape.insert(pos);
++pos;
state = 'A';
} else {
tape.insert(pos);
++pos;
state = 'E';
}
break;
}
}
std::cout << tape.size() << "\n";
return 0;
}