File tree 3 files changed +192
-0
lines changed
3 files changed +192
-0
lines changed Original file line number Diff line number Diff line change
1
+ noop
2
+ noop
3
+ noop
4
+ addx 6
5
+ noop
6
+ addx 30
7
+ addx -26
8
+ noop
9
+ addx 5
10
+ noop
11
+ noop
12
+ noop
13
+ noop
14
+ addx 5
15
+ addx -5
16
+ addx 6
17
+ addx 5
18
+ addx -1
19
+ addx 5
20
+ noop
21
+ noop
22
+ addx -14
23
+ addx -18
24
+ addx 39
25
+ addx -39
26
+ addx 25
27
+ addx -22
28
+ addx 2
29
+ addx 5
30
+ addx 2
31
+ addx 3
32
+ addx -2
33
+ addx 2
34
+ noop
35
+ addx 3
36
+ addx 2
37
+ addx 2
38
+ noop
39
+ addx 3
40
+ noop
41
+ addx 3
42
+ addx 2
43
+ addx 5
44
+ addx 4
45
+ addx -18
46
+ addx 17
47
+ addx -38
48
+ addx 5
49
+ addx 2
50
+ addx -5
51
+ addx 27
52
+ addx -19
53
+ noop
54
+ addx 3
55
+ addx 4
56
+ noop
57
+ noop
58
+ addx 5
59
+ addx -1
60
+ noop
61
+ noop
62
+ addx 4
63
+ addx 5
64
+ addx 2
65
+ addx -4
66
+ addx 5
67
+ noop
68
+ addx -11
69
+ addx 16
70
+ addx -36
71
+ noop
72
+ addx 5
73
+ noop
74
+ addx 28
75
+ addx -23
76
+ noop
77
+ noop
78
+ noop
79
+ addx 21
80
+ addx -18
81
+ noop
82
+ addx 3
83
+ addx 2
84
+ addx 2
85
+ addx 5
86
+ addx 1
87
+ noop
88
+ noop
89
+ addx 4
90
+ noop
91
+ noop
92
+ noop
93
+ noop
94
+ noop
95
+ addx 8
96
+ addx -40
97
+ noop
98
+ addx 7
99
+ noop
100
+ addx -2
101
+ addx 5
102
+ addx 2
103
+ addx 25
104
+ addx -31
105
+ addx 9
106
+ addx 5
107
+ addx 2
108
+ addx 2
109
+ addx 3
110
+ addx -2
111
+ noop
112
+ addx 3
113
+ addx 2
114
+ noop
115
+ addx 7
116
+ addx -2
117
+ addx 5
118
+ addx -40
119
+ addx 20
120
+ addx -12
121
+ noop
122
+ noop
123
+ noop
124
+ addx -5
125
+ addx 7
126
+ addx 7
127
+ noop
128
+ addx -1
129
+ addx 1
130
+ addx 5
131
+ addx 3
132
+ addx -2
133
+ addx 2
134
+ noop
135
+ addx 3
136
+ addx 2
137
+ noop
138
+ noop
139
+ noop
140
+ noop
141
+ addx 7
142
+ noop
143
+ noop
144
+ noop
145
+ noop
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env ruby
2
+
3
+ $signalStrengths = [ ]
4
+ $cycle = $x = 1
5
+ ops = File . readlines ( "input.txt" , chomp : true ) . reverse
6
+
7
+ while not ops . empty? do
8
+ ( op , n ) = ops . pop ( ) &.split ( " " )
9
+ if op == "noop" or op == nil then
10
+ elsif op == "_addx" then
11
+ $x += n . to_i
12
+ next
13
+ elsif op == "addx" then
14
+ ops . push ( "_addx " + n , nil )
15
+ end
16
+
17
+ # Tick
18
+ if $cycle >= 20 and ( $cycle - 20 ) % 40 == 0 then
19
+ $signalStrengths. push ( $cycle * $x)
20
+ end
21
+ $cycle += 1
22
+ end
23
+
24
+ p $signalStrengths. sum
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env ruby
2
+
3
+ $screen = [ ]
4
+ $cycle = 0
5
+ $x = 1
6
+ ops = File . readlines ( "input.txt" , chomp : true ) . reverse
7
+
8
+ while not ops . empty? do
9
+ ( op , n ) = ops . pop ( ) &.split ( " " )
10
+ if op == "noop" or op == nil then
11
+ elsif op == "_addx" then
12
+ $x += n . to_i
13
+ next
14
+ elsif op == "addx" then
15
+ ops . push ( "_addx " + n , nil )
16
+ end
17
+
18
+ # Tick
19
+ $screen. push ( ( $cycle % 40 ) . between? ( $x - 1 , $x + 1 ) ? "#" : " " )
20
+ $cycle += 1
21
+ end
22
+
23
+ $screen. each_slice ( 40 ) { |slice | p slice . join ( ) }
You can’t perform that action at this time.
0 commit comments