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