File tree 5 files changed +343
-0
lines changed
5 files changed +343
-0
lines changed Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env pypy3
2
+
3
+ import sys
4
+
5
+ def strength (cycle , x ):
6
+ return cycle * x if not (cycle - 20 ) % 40 else 0
7
+
8
+ def main ():
9
+ x = 1
10
+ cycle = 1
11
+ strength_sum = 0
12
+ for line in sys .stdin :
13
+ strength_sum += strength (cycle , x )
14
+ instruction = line .split ()
15
+ if instruction [0 ] == 'addx' :
16
+ strength_sum += strength (cycle + 1 , x )
17
+ x += int (instruction [1 ])
18
+ cycle += 2
19
+ else :
20
+ cycle += 1
21
+
22
+ print (strength_sum )
23
+
24
+ if __name__ == '__main__' :
25
+ main ()
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env pypy3
2
+
3
+ import sys
4
+
5
+ CRT_W = 40
6
+ CRT_H = 6
7
+
8
+ def crt_update (crt , cycle , x ):
9
+ row = (cycle - 1 ) // 40
10
+ col = (cycle - 1 ) % 40
11
+ if abs (x - col ) <= 1 :
12
+ crt [row ][col ] = '#'
13
+
14
+ def main ():
15
+ x = 1
16
+ cycle = 1
17
+ crt = [['.' for _ in range (CRT_W )] for _ in range (CRT_H )]
18
+ for line in sys .stdin :
19
+ crt_update (crt , cycle , x )
20
+ instruction = line .split ()
21
+ if instruction [0 ] == 'addx' :
22
+ crt_update (crt , cycle + 1 , x )
23
+ x += int (instruction [1 ])
24
+ cycle += 2
25
+ else :
26
+ cycle += 1
27
+
28
+ print ('\n ' .join ('' .join (row ) for row in crt ))
29
+
30
+ if __name__ == '__main__' :
31
+ main ()
Original file line number Diff line number Diff line change
1
+ addx 1
2
+ addx 5
3
+ addx -1
4
+ addx 20
5
+ addx -14
6
+ addx -1
7
+ addx 5
8
+ addx 13
9
+ addx -12
10
+ addx 3
11
+ addx 3
12
+ addx 3
13
+ addx 1
14
+ addx 4
15
+ noop
16
+ noop
17
+ addx 1
18
+ noop
19
+ noop
20
+ addx 4
21
+ noop
22
+ addx -35
23
+ addx 11
24
+ addx -1
25
+ addx -7
26
+ addx 5
27
+ addx 2
28
+ addx 3
29
+ addx -2
30
+ addx 2
31
+ addx 5
32
+ addx 5
33
+ noop
34
+ noop
35
+ addx -2
36
+ addx 2
37
+ noop
38
+ addx 3
39
+ addx 2
40
+ addx 7
41
+ noop
42
+ noop
43
+ addx 3
44
+ addx -2
45
+ addx -36
46
+ noop
47
+ addx 25
48
+ addx -22
49
+ addx 7
50
+ noop
51
+ addx -2
52
+ noop
53
+ noop
54
+ noop
55
+ addx 5
56
+ addx 5
57
+ addx 4
58
+ noop
59
+ addx -2
60
+ addx 5
61
+ addx -4
62
+ addx 5
63
+ addx 4
64
+ noop
65
+ addx -29
66
+ addx 32
67
+ addx -23
68
+ addx -12
69
+ noop
70
+ addx 7
71
+ noop
72
+ addx -2
73
+ addx 4
74
+ addx 3
75
+ addx 20
76
+ addx 3
77
+ addx -20
78
+ addx 5
79
+ addx 16
80
+ addx -15
81
+ addx 6
82
+ noop
83
+ noop
84
+ noop
85
+ addx 5
86
+ noop
87
+ addx 5
88
+ noop
89
+ noop
90
+ noop
91
+ addx -37
92
+ addx 2
93
+ addx -2
94
+ addx 7
95
+ noop
96
+ addx -2
97
+ addx 5
98
+ addx 2
99
+ addx 3
100
+ addx -2
101
+ addx 2
102
+ addx 5
103
+ addx 2
104
+ addx -6
105
+ addx -15
106
+ addx 24
107
+ addx 2
108
+ noop
109
+ addx 3
110
+ addx -8
111
+ addx 15
112
+ addx -14
113
+ addx 15
114
+ addx -38
115
+ noop
116
+ noop
117
+ addx 21
118
+ addx -14
119
+ addx 1
120
+ addx 5
121
+ noop
122
+ addx -2
123
+ addx 7
124
+ addx -1
125
+ addx 5
126
+ noop
127
+ addx 2
128
+ addx 3
129
+ addx 3
130
+ addx -2
131
+ addx 4
132
+ addx 2
133
+ addx -17
134
+ addx 20
135
+ noop
136
+ noop
137
+ noop
138
+ noop
Original file line number Diff line number Diff line change
1
+ noop
2
+ addx 3
3
+ addx -5
Original file line number Diff line number Diff line change
1
+ addx 15
2
+ addx -11
3
+ addx 6
4
+ addx -3
5
+ addx 5
6
+ addx -1
7
+ addx -8
8
+ addx 13
9
+ addx 4
10
+ noop
11
+ addx -1
12
+ addx 5
13
+ addx -1
14
+ addx 5
15
+ addx -1
16
+ addx 5
17
+ addx -1
18
+ addx 5
19
+ addx -1
20
+ addx -35
21
+ addx 1
22
+ addx 24
23
+ addx -19
24
+ addx 1
25
+ addx 16
26
+ addx -11
27
+ noop
28
+ noop
29
+ addx 21
30
+ addx -15
31
+ noop
32
+ noop
33
+ addx -3
34
+ addx 9
35
+ addx 1
36
+ addx -3
37
+ addx 8
38
+ addx 1
39
+ addx 5
40
+ noop
41
+ noop
42
+ noop
43
+ noop
44
+ noop
45
+ addx -36
46
+ noop
47
+ addx 1
48
+ addx 7
49
+ noop
50
+ noop
51
+ noop
52
+ addx 2
53
+ addx 6
54
+ noop
55
+ noop
56
+ noop
57
+ noop
58
+ noop
59
+ addx 1
60
+ noop
61
+ noop
62
+ addx 7
63
+ addx 1
64
+ noop
65
+ addx -13
66
+ addx 13
67
+ addx 7
68
+ noop
69
+ addx 1
70
+ addx -33
71
+ noop
72
+ noop
73
+ noop
74
+ addx 2
75
+ noop
76
+ noop
77
+ noop
78
+ addx 8
79
+ noop
80
+ addx -1
81
+ addx 2
82
+ addx 1
83
+ noop
84
+ addx 17
85
+ addx -9
86
+ addx 1
87
+ addx 1
88
+ addx -3
89
+ addx 11
90
+ noop
91
+ noop
92
+ addx 1
93
+ noop
94
+ addx 1
95
+ noop
96
+ noop
97
+ addx -13
98
+ addx -19
99
+ addx 1
100
+ addx 3
101
+ addx 26
102
+ addx -30
103
+ addx 12
104
+ addx -1
105
+ addx 3
106
+ addx 1
107
+ noop
108
+ noop
109
+ noop
110
+ addx -9
111
+ addx 18
112
+ addx 1
113
+ addx 2
114
+ noop
115
+ noop
116
+ addx 9
117
+ noop
118
+ noop
119
+ noop
120
+ addx -1
121
+ addx 2
122
+ addx -37
123
+ addx 1
124
+ addx 3
125
+ noop
126
+ addx 15
127
+ addx -21
128
+ addx 22
129
+ addx -6
130
+ addx 1
131
+ noop
132
+ addx 2
133
+ addx 1
134
+ noop
135
+ addx -10
136
+ noop
137
+ noop
138
+ addx 20
139
+ addx 1
140
+ addx 2
141
+ addx 2
142
+ addx -6
143
+ addx -11
144
+ noop
145
+ noop
146
+ noop
You can’t perform that action at this time.
0 commit comments