File tree Expand file tree Collapse file tree 3 files changed +205
-9
lines changed Expand file tree Collapse file tree 3 files changed +205
-9
lines changed Original file line number Diff line number Diff line change
1
+ package Day10 ;
2
+
3
+ import java .util .HashMap ;
4
+ import java .util .List ;
5
+ import java .util .Map ;
6
+
7
+ /**
8
+ * @author Inna Pirina
9
+ * @since 10.12.2022
10
+ */
11
+ public class CircuitReader {
12
+
13
+ private final Map <Integer , Integer > cycleSignals ;
14
+
15
+ public CircuitReader () {
16
+ cycleSignals = new HashMap <>();
17
+ }
18
+
19
+ public void readCircuit (List <String > cycles ) {
20
+ int currentCycle = 1 ;
21
+ int currentX = 1 ;
22
+
23
+ for (String cycleOperation : cycles ) {
24
+ cycleSignals .put (currentCycle , currentX );
25
+ if (!cycleOperation .equalsIgnoreCase ("noop" )) {
26
+ String [] operation = cycleOperation .split (" " );
27
+ cycleSignals .put (++currentCycle , currentX );
28
+ currentX += Integer .parseInt (operation [1 ]);
29
+ }
30
+ currentCycle ++;
31
+ }
32
+ cycleSignals .put (currentCycle , currentX );
33
+ }
34
+
35
+ public int sumSinalStrengths () {
36
+ return 20 * cycleSignals .get (20 ) + 60 * cycleSignals .get (60 ) + 100 * cycleSignals .get (100 )
37
+ + 140 * cycleSignals .get (140 ) + 180 * cycleSignals .get (180 ) + 220 * cycleSignals .get (220 );
38
+ }
39
+
40
+ public void printCycleSignals () {
41
+ int currentX = 0 ;
42
+ for (int cycle = 1 ; cycle <= cycleSignals .size (); cycle ++) {
43
+ Integer signal = cycleSignals .get (cycle );
44
+ if (currentX == signal - 1 || currentX == signal || currentX == signal + 1 ) {
45
+ System .out .print ("#" );
46
+ } else {
47
+ System .out .print (" " );
48
+ }
49
+
50
+ if (currentX == 39 ) {
51
+ System .out .println ();
52
+ currentX = 0 ;
53
+ } else {
54
+ currentX ++;
55
+ }
56
+ }
57
+ }
58
+ }
Original file line number Diff line number Diff line change 1
1
package Day10 ;
2
2
3
- import java .util .Collections ;
3
+ import static advent .utils .AdventFileUtils .readInputIntoStringLines ;
4
+
4
5
import java .util .List ;
5
6
6
7
public class Day10Main {
7
8
8
9
public static void main (String [] args ) {
10
+ List <String > inputAsLines = getInput ();
11
+ CircuitReader circuitReader = new CircuitReader ();
12
+ circuitReader .readCircuit (inputAsLines );
9
13
10
- System .out .println ("Here we go!" );
11
-
12
- // read input
13
-
14
- // print puzzle solutions
15
-
14
+ int signalStrengths = circuitReader .sumSinalStrengths ();
15
+ System .out .println (signalStrengths );
16
+ circuitReader .printCycleSignals ();
16
17
}
17
18
18
- protected static List <Integer > getInput () {
19
- return Collections . emptyList ( );
19
+ protected static List <String > getInput () {
20
+ return readInputIntoStringLines ( Day10Main . class );
20
21
}
21
22
}
Original file line number Diff line number Diff line change
1
+ addx 1
2
+ noop
3
+ addx 2
4
+ addx 5
5
+ addx 2
6
+ noop
7
+ noop
8
+ noop
9
+ addx 5
10
+ noop
11
+ noop
12
+ addx 1
13
+ addx 2
14
+ addx -5
15
+ addx 12
16
+ addx 1
17
+ addx 4
18
+ addx 2
19
+ noop
20
+ addx -1
21
+ addx 4
22
+ noop
23
+ noop
24
+ addx -37
25
+ addx 21
26
+ addx -13
27
+ addx -3
28
+ noop
29
+ addx 3
30
+ addx 2
31
+ addx 5
32
+ addx -2
33
+ addx 7
34
+ addx -2
35
+ addx 2
36
+ addx 11
37
+ addx -4
38
+ addx 3
39
+ noop
40
+ addx -18
41
+ addx 7
42
+ addx 14
43
+ addx 2
44
+ addx 5
45
+ addx -39
46
+ addx 1
47
+ addx 5
48
+ noop
49
+ noop
50
+ noop
51
+ addx 1
52
+ addx 4
53
+ noop
54
+ addx 12
55
+ addx 10
56
+ addx -17
57
+ addx 5
58
+ addx -17
59
+ addx 14
60
+ addx 6
61
+ noop
62
+ addx 3
63
+ addx 7
64
+ noop
65
+ noop
66
+ addx 2
67
+ addx 3
68
+ noop
69
+ addx -40
70
+ addx 40
71
+ addx -33
72
+ addx -2
73
+ noop
74
+ addx 3
75
+ addx 2
76
+ addx 5
77
+ addx -7
78
+ addx 8
79
+ noop
80
+ addx 6
81
+ addx 8
82
+ addx -11
83
+ addx 8
84
+ noop
85
+ addx -19
86
+ addx 27
87
+ noop
88
+ addx -2
89
+ addx 4
90
+ noop
91
+ addx -10
92
+ addx -27
93
+ noop
94
+ noop
95
+ addx 7
96
+ addx 4
97
+ addx -3
98
+ addx 2
99
+ addx 5
100
+ addx 2
101
+ addx -4
102
+ addx -3
103
+ addx 10
104
+ addx 15
105
+ addx -8
106
+ addx 2
107
+ addx 3
108
+ addx -2
109
+ addx 5
110
+ addx 2
111
+ addx 2
112
+ addx -39
113
+ addx 1
114
+ addx 3
115
+ addx 3
116
+ addx 3
117
+ noop
118
+ addx 2
119
+ addx 1
120
+ addx 4
121
+ addx -1
122
+ addx 2
123
+ addx 4
124
+ addx 1
125
+ noop
126
+ noop
127
+ addx 2
128
+ addx 5
129
+ addx 3
130
+ noop
131
+ noop
132
+ addx -27
133
+ addx 29
134
+ noop
135
+ addx 3
136
+ noop
137
+ noop
You can’t perform that action at this time.
0 commit comments