-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay25.java
107 lines (99 loc) · 2.11 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
import java.util.HashSet;
import java.util.Set;
public class Day25 {
enum State {
A,
B,
C,
D,
E,
F
}
private static int part1(int input) {
Set<Integer> oneIdx = new HashSet<>();
State state = State.A;
int currentIdx = 0;
for (int i = 0; i < input; i++) {
int currentValue = oneIdx.contains(currentIdx) ? 1 : 0;
switch (state) {
case A:
if (currentValue == 0) {
oneIdx.add(currentIdx);
currentIdx++;
state = State.B;
}
else {
oneIdx.remove(currentIdx);
currentIdx++;
state = State.C;
}
break;
case B:
if (currentValue == 0) {
oneIdx.remove(currentIdx);
currentIdx--;
state = State.A;
}
else {
oneIdx.remove(currentIdx);
currentIdx++;
state = State.D;
}
break;
case C:
if (currentValue == 0) {
oneIdx.add(currentIdx);
currentIdx++;
state = State.D;
}
else {
oneIdx.add(currentIdx);
currentIdx++;
state = State.A;
}
break;
case D:
if (currentValue == 0) {
oneIdx.add(currentIdx);
currentIdx--;
state = State.E;
}
else {
oneIdx.remove(currentIdx);
currentIdx--;
state = State.D;
}
break;
case E:
if (currentValue == 0) {
oneIdx.add(currentIdx);
currentIdx++;
state = State.F;
}
else {
oneIdx.add(currentIdx);
currentIdx--;
state = State.B;
}
break;
case F:
if (currentValue == 0) {
oneIdx.add(currentIdx);
currentIdx++;
state = State.A;
}
else {
oneIdx.add(currentIdx);
currentIdx++;
state = State.E;
}
break;
}
}
return oneIdx.size();
}
public static void main(String[] args) {
int input = 12368930;
System.out.println(part1(input));
}
}