-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathDay25.java
109 lines (95 loc) · 2.02 KB
/
Day25.java
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
package aoc17;
import java.util.HashSet;
import java.util.Set;
/**
* NOTE: This is not a universal solution. I don't know if other input only
* differs in the stepcount. If they do, it's a universal solution. Otherwise, it
* isnt.
*
* @author Timucin Merdin
*
*/
public class Day25 {
private final int STEP_COUNT;
public Day25(int stepCount) {
this.STEP_COUNT = stepCount;
}
public int getChecksum() {
char state = 'A';
// all the tape positions containing a 1
Set<Integer> tapeValuesOne = new HashSet<>();
int steps = 0;
int cursor = 0;
while (steps < STEP_COUNT) {
if (state == 'A') {
if (tapeValuesOne.contains(cursor)) {
tapeValuesOne.remove(cursor);
cursor++;
state = 'F';
} else {
tapeValuesOne.add(cursor);
cursor++;
state = 'B';
}
}
else if (state == 'B') {
if (tapeValuesOne.contains(cursor)) {
cursor--;
state = 'C';
} else {
cursor--;
state = 'B';
}
}
else if (state == 'C') {
if (tapeValuesOne.contains(cursor)) {
tapeValuesOne.remove(cursor);
cursor++;
state = 'C';
} else {
tapeValuesOne.add(cursor);
cursor--;
state = 'D';
}
}
else if (state == 'D') {
if (tapeValuesOne.contains(cursor)) {
cursor++;
state = 'A';
} else {
tapeValuesOne.add(cursor);
cursor--;
state = 'E';
}
}
else if (state == 'E') {
if (tapeValuesOne.contains(cursor)) {
tapeValuesOne.remove(cursor);
cursor--;
state = 'D';
} else {
tapeValuesOne.add(cursor);
cursor--;
state = 'F';
}
}
else if (state == 'F') {
if (tapeValuesOne.contains(cursor)) {
tapeValuesOne.remove(cursor);
cursor--;
state = 'E';
} else {
tapeValuesOne.add(cursor);
cursor++;
state = 'A';
}
}
steps++;
}
return tapeValuesOne.size();
}
public static void main(String[] args) {
Day25 test = new Day25(12425180);
System.out.println(test.getChecksum());
}
}