summaryrefslogtreecommitdiffstats
path: root/2020/day8
diff options
context:
space:
mode:
authorYigit Sever2021-12-13 10:38:11 +0300
committerYigit Sever2021-12-13 10:38:11 +0300
commit74b27ccca31bb757c737dd7fdc02f513f57561b2 (patch)
treee27db4cd0873c81a53d32277446d926d176304e0 /2020/day8
parent3919f90cfbfbba26c8e39f979280649f5e08aea8 (diff)
parentac8125750abed263619da4cc6d653bb5ab76f007 (diff)
downloadaoc-74b27ccca31bb757c737dd7fdc02f513f57561b2.tar.gz
aoc-74b27ccca31bb757c737dd7fdc02f513f57561b2.tar.bz2
aoc-74b27ccca31bb757c737dd7fdc02f513f57561b2.zip
Merge remote-tracking branch 'origin/main'
Diffstat (limited to '2020/day8')
-rw-r--r--2020/day8/gamechild.py55
-rw-r--r--2020/day8/handheld.py27
-rw-r--r--2020/day8/input642
3 files changed, 724 insertions, 0 deletions
diff --git a/2020/day8/gamechild.py b/2020/day8/gamechild.py
new file mode 100644
index 0000000..3763c78
--- /dev/null
+++ b/2020/day8/gamechild.py
@@ -0,0 +1,55 @@
1boot_code = list()
2
3
4def gameon(acc, cx, sf):
5 """emulates the game until a loop or the end"""
6
7 while cx not in sf:
8 sf.add(cx)
9
10 if cx == len(boot_code):
11 print(acc)
12 exit(0)
13
14 if boot_code[cx][0] == "acc":
15 acc += boot_code[cx][1]
16 elif boot_code[cx][0] == "jmp":
17 cx += boot_code[cx][1] - 1
18 else: # nop
19 pass
20
21 cx += 1
22
23
24with open("input", "r") as file:
25 for line in file:
26 line = line.strip()
27 oparg = line.split(" ")
28 boot_code.append((oparg[0], int(oparg[1])))
29
30
31cursor = 0
32accumulator = 0
33sofar = set()
34
35# we are allowed to keep a 'main' branch and keep jmp/nops separate because
36# task calls for only one instruction change over the whole code
37
38while cursor not in sofar:
39 sofar.add(cursor)
40
41 if boot_code[cursor][0] == "acc":
42 accumulator += boot_code[cursor][1]
43 elif boot_code[cursor][0] == "jmp":
44 # one for the jmp
45 gameon(accumulator, cursor + boot_code[cursor][1], sofar.copy())
46 # one for the nop
47 gameon(accumulator, cursor + 1, sofar.copy())
48 cursor += boot_code[cursor][1] - 1
49 elif boot_code[cursor][0] == "nop":
50 # one for the nop
51 gameon(accumulator, cursor + 1, sofar.copy())
52 # one for the jmp
53 gameon(accumulator, cursor + boot_code[cursor][1], sofar.copy())
54
55 cursor += 1
diff --git a/2020/day8/handheld.py b/2020/day8/handheld.py
new file mode 100644
index 0000000..6197a2f
--- /dev/null
+++ b/2020/day8/handheld.py
@@ -0,0 +1,27 @@
1boot_code = list()
2with open("input", "r") as file:
3 for line in file:
4 line = line.strip()
5 oparg = line.split(" ")
6 boot_code.append((oparg[0], int(oparg[1])))
7
8
9cursor = 0
10
11accumulator = 0
12
13sofar = set()
14
15while cursor not in sofar:
16 sofar.add(cursor)
17
18 if boot_code[cursor][0] == "acc":
19 accumulator += boot_code[cursor][1]
20 elif boot_code[cursor][0] == "jmp":
21 cursor += boot_code[cursor][1] - 1
22 else:
23 pass
24
25 cursor += 1
26
27print(accumulator)
diff --git a/2020/day8/input b/2020/day8/input
new file mode 100644
index 0000000..a73cabd
--- /dev/null
+++ b/2020/day8/input
@@ -0,0 +1,642 @@
1acc +40
2acc -14
3nop +386
4jmp +262
5acc -4
6nop +25
7jmp +500
8acc +13
9acc -1
10acc -7
11acc +37
12jmp +319
13acc +46
14jmp +429
15acc -4
16acc -8
17jmp +335
18acc +12
19jmp +78
20acc +16
21acc -11
22nop +137
23acc +41
24jmp +210
25jmp +83
26acc +7
27jmp +48
28nop +374
29acc +11
30jmp +268
31acc +1
32acc -17
33acc +15
34jmp +178
35acc +23
36jmp -5
37jmp +374
38acc +8
39acc +5
40nop +231
41jmp +1
42jmp -22
43acc +44
44acc +39
45jmp +415
46acc +44
47acc -8
48acc -10
49jmp +36
50nop +385
51acc +6
52jmp -37
53nop +245
54acc +5
55jmp +261
56acc -3
57jmp +23
58acc +37
59jmp +532
60acc -18
61acc -8
62nop +405
63jmp +499
64acc -1
65acc +3
66acc +47
67acc +38
68jmp +67
69jmp -9
70acc +16
71acc -4
72acc +23
73acc +6
74jmp -14
75jmp +229
76nop +235
77acc +3
78acc +17
79jmp +521
80acc +49
81acc -8
82acc +10
83jmp +103
84jmp +75
85acc +22
86nop +527
87acc +36
88acc +32
89jmp -46
90nop +434
91jmp +447
92jmp +159
93acc +37
94acc -19
95acc +39
96jmp +181
97jmp +1
98jmp +162
99jmp +1
100acc +0
101acc +0
102acc +34
103jmp +241
104acc +42
105acc +12
106jmp -75
107jmp -70
108acc +42
109acc -4
110acc +49
111jmp +456
112jmp +277
113jmp +302
114acc +45
115acc +19
116nop -41
117jmp +318
118jmp +153
119acc +9
120nop +323
121jmp -113
122nop -9
123jmp +1
124acc +37
125acc +12
126jmp +448
127acc +3
128acc +38
129jmp -114
130acc +7
131jmp +180
132acc -5
133acc -10
134jmp +117
135jmp +320
136acc +9
137jmp +330
138acc +18
139jmp +1
140jmp +330
141nop +450
142acc +10
143jmp +22
144acc +44
145jmp +298
146acc +38
147nop +433
148acc +1
149jmp +431
150jmp +339
151nop +251
152jmp -126
153nop +191
154jmp +294
155acc -7
156acc +30
157acc -15
158jmp +400
159jmp +441
160acc +5
161acc +17
162nop +35
163nop +103
164jmp +410
165nop -122
166acc +35
167jmp +73
168acc -13
169jmp +291
170acc -11
171jmp +95
172acc -12
173acc +19
174acc -16
175acc +34
176jmp +140
177acc -15
178acc +6
179acc -4
180jmp +190
181acc +11
182acc +0
183acc +19
184acc +43
185jmp +167
186acc +29
187nop +371
188jmp +1
189jmp -36
190acc +20
191acc +20
192acc +26
193jmp +374
194jmp -76
195acc +20
196jmp +115
197acc +13
198acc +25
199acc +39
200jmp -115
201acc -18
202nop -64
203jmp +133
204acc -18
205acc +32
206nop -198
207jmp -157
208acc +6
209acc +41
210nop +36
211jmp -136
212jmp +1
213jmp +41
214acc -14
215acc -17
216acc +1
217jmp +280
218jmp +1
219jmp +72
220acc +7
221jmp +1
222acc -12
223acc -8
224jmp +291
225acc -13
226acc +36
227acc +0
228jmp +97
229acc +20
230acc +0
231acc +12
232acc -16
233jmp -196
234nop +342
235jmp -122
236acc +21
237nop -33
238acc +38
239jmp +285
240acc -9
241acc -17
242acc -2
243acc +25
244jmp +232
245jmp +146
246jmp +312
247acc +11
248nop -54
249nop +351
250jmp -46
251acc +27
252jmp -244
253jmp +262
254acc +42
255acc +5
256nop +4
257acc +20
258jmp +239
259jmp -62
260nop -147
261jmp -169
262acc -12
263acc +40
264acc +29
265jmp +178
266nop +310
267jmp +49
268acc -18
269acc +5
270jmp +297
271jmp +244
272acc +31
273acc +21
274acc +47
275acc +41
276jmp +76
277acc +29
278acc +22
279acc +16
280jmp -121
281jmp -244
282acc +45
283acc -9
284acc +36
285acc +5
286jmp +265
287acc +13
288acc +47
289acc -11
290jmp +338
291acc +0
292jmp +85
293acc +18
294acc +27
295jmp +1
296acc +43
297jmp +227
298jmp +276
299acc +42
300nop +52
301acc -15
302nop +311
303jmp -199
304acc +45
305jmp +286
306acc -8
307acc +7
308acc +9
309acc -18
310jmp -273
311acc +50
312jmp +239
313nop +31
314acc +16
315jmp -162
316acc +12
317nop -204
318acc +27
319jmp -166
320acc -4
321acc +38
322acc +50
323nop +120
324jmp +243
325acc +29
326jmp -300
327acc +0
328nop +179
329acc -6
330jmp -136
331nop -305
332acc +15
333jmp -136
334acc -6
335jmp +172
336jmp +41
337acc -7
338nop +81
339jmp +199
340jmp +54
341acc +1
342acc +25
343jmp -283
344nop -132
345acc +47
346jmp +239
347acc +45
348acc -14
349acc +1
350acc +0
351jmp +10
352acc -15
353nop -338
354nop -257
355jmp +1
356jmp -218
357acc +36
358acc +33
359acc +28
360jmp -230
361acc -5
362acc -14
363jmp +1
364jmp -87
365acc +48
366nop +141
367nop +224
368acc +42
369jmp +22
370nop +140
371acc +16
372jmp +1
373acc +16
374jmp -92
375acc +37
376jmp -368
377acc +27
378jmp +155
379acc +11
380nop +196
381acc +5
382jmp -269
383nop -92
384jmp -276
385acc +46
386acc +6
387acc +34
388jmp -258
389jmp +2
390jmp +80
391jmp +36
392acc +20
393jmp -181
394nop -54
395acc +48
396nop +166
397nop +165
398jmp -263
399acc +47
400acc +33
401jmp +54
402nop -216
403acc +37
404acc +19
405jmp -349
406acc +12
407nop -156
408nop +7
409acc -5
410jmp -390
411acc -10
412jmp -315
413nop -393
414jmp -89
415jmp +1
416jmp -312
417acc +4
418jmp -120
419acc -2
420nop +23
421acc +42
422acc +28
423jmp -205
424acc +43
425acc +6
426jmp -49
427acc -13
428acc +1
429acc +10
430acc +19
431jmp -394
432acc -15
433acc +0
434jmp -365
435acc +23
436acc -17
437nop +23
438acc +0
439jmp -37
440acc +9
441acc +31
442jmp -7
443jmp -278
444nop +147
445acc +5
446acc +43
447jmp -149
448nop -65
449acc +19
450acc +46
451jmp +59
452acc +29
453nop +169
454jmp +131
455acc +43
456acc +50
457jmp +10
458acc -4
459jmp -390
460acc +24
461jmp -236
462acc +10
463acc +19
464nop -160
465acc +32
466jmp +162
467acc +29
468jmp +170
469jmp -14
470acc +36
471jmp -88
472acc +2
473acc +1
474acc +1
475jmp -86
476nop +48
477acc +21
478jmp -356
479acc +0
480nop -321
481nop -247
482nop +127
483jmp -279
484jmp +40
485acc +23
486acc +47
487acc +6
488jmp -438
489acc +26
490acc +35
491nop +120
492acc +2
493jmp -58
494acc +30
495acc +2
496jmp +42
497acc +8
498acc +24
499acc +9
500acc +19
501jmp -351
502acc +40
503acc +18
504acc +43
505acc +29
506jmp +9
507jmp +1
508jmp -210
509jmp -82
510acc +41
511acc +45
512jmp -28
513nop -395
514jmp +71
515acc +38
516acc -13
517nop -251
518acc -9
519jmp -366
520acc +34
521acc +7
522acc -7
523jmp -212
524acc +6
525acc +24
526acc +1
527acc -11
528jmp +94
529acc +20
530acc -14
531acc -5
532jmp +81
533acc +37
534jmp +77
535acc -15
536nop -486
537jmp +39
538jmp +1
539acc +39
540acc +49
541jmp -371
542acc +5
543nop -446
544jmp -267
545acc +39
546jmp +67
547acc +35
548acc +8
549nop -419
550jmp -53
551acc +20
552acc -9
553acc +46
554acc +30
555jmp -136
556acc +35
557jmp +56
558jmp +70
559acc +13
560acc +48
561jmp -290
562acc -18
563acc +48
564acc +50
565jmp -225
566jmp -226
567acc +34
568jmp -391
569acc +49
570nop -324
571acc -10
572acc +41
573jmp -130
574jmp +6
575jmp -555
576acc -17
577jmp -433
578acc +33
579jmp -64
580jmp -476
581nop -138
582nop -556
583acc +47
584jmp +27
585jmp -78
586acc -16
587acc -4
588acc -3
589acc +48
590jmp -292
591acc +43
592acc +3
593acc +44
594jmp +15
595acc +49
596acc +5
597acc +4
598acc +27
599jmp -491
600acc +6
601acc +38
602acc +31
603nop -70
604jmp -379
605acc +0
606acc +2
607acc +49
608jmp -297
609jmp -405
610jmp -72
611jmp -371
612jmp -115
613acc +7
614acc -15
615acc -9
616jmp -486
617acc +3
618acc +16
619nop -19
620acc +14
621jmp -296
622jmp -233
623acc +40
624nop -342
625nop -58
626acc -9
627jmp -316
628acc +4
629acc +15
630acc +14
631acc +50
632jmp -296
633acc -11
634acc +14
635acc +43
636acc +38
637jmp -391
638acc +43
639acc +25
640acc -5
641acc +27
642jmp +1