diff options
| author | nekineki <nekineki@nekineki.net> | 2022-12-10 07:30:42 +0100 |
|---|---|---|
| committer | nekineki <nekineki@nekineki.net> | 2022-12-10 07:30:42 +0100 |
| commit | fe9cdd83b907a2ff9ce1fd6b1522808ca1015a4a (patch) | |
| tree | b5ae1eec3af071c8e07e5917b6a956ce39b54b8a /2022 | |
| parent | 5fa27fd67ff153ab161a2d671e6d3b7082b8be0e (diff) | |
day10
Diffstat (limited to '2022')
| -rwxr-xr-x | 2022/day10/asd.py | 71 | ||||
| -rw-r--r-- | 2022/day10/pzl.txt | 145 | ||||
| -rw-r--r-- | 2022/day10/ref.txt | 146 |
3 files changed, 362 insertions, 0 deletions
diff --git a/2022/day10/asd.py b/2022/day10/asd.py new file mode 100755 index 0000000..7281026 --- /dev/null +++ b/2022/day10/asd.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python3 + +# import numpy as np +from functools import reduce +from re import findall +from copy import deepcopy +import sys + +# filename = "ref.txt" +filename = "pzl.txt" +data = open(filename).read() +lines = [line for line in data.rstrip('\n').split('\n')] + +res1 = 0 +x = 1 +cycles = 1 +for line in lines: + opcodes = line.split(' ') + if opcodes[0] == 'addx': + if cycles == 19 or (cycles+20) % 40 == 39: + a = (cycles+1) * x + res1 += a + elif cycles == 20 or (cycles+20) % 40 == 0: + a = cycles * x + res1 += a + x += int(opcodes[1]) + cycles += 2 + elif opcodes[0] == 'noop': + if cycles == 20 or (cycles+20) % 40 == 0: + a = cycles * x + res1 += a + cycles += 1 + + +res2 = 'read it' +crt = [0 for _ in range(40*6)] +x = 1 +cycles = 1 +def print_crt(crt): + for i,val in enumerate(crt): + print('.' if val == 0 else '#', end='') + if (i+1) % 40 == 0: + print() + print() + +def sprite(crt, cycles, x): + s = [1 if abs(x-i) % 40 in [39, 0, 1] else 0 for i in range(40*6)] + c = [1 if abs(cycles-i-1) % (40*6) == 0 else 0 for i in range(40*6)] + + m = list(map(lambda x: x[0]*x[1], zip(c,s))) + crt = list(map(lambda x: x[0]+x[1], zip(crt,m))) + return crt + +for line in lines: + opcodes = line.split(' ') + if opcodes[0] == 'addx': + crt = sprite(crt, cycles+0, x) + crt = sprite(crt, cycles+1, x) + x += int(opcodes[1]) + cycles += 2 + elif opcodes[0] == 'noop': + crt = sprite(crt, cycles+0, x) + a = cycles * x + cycles += 1 + # print(cycles, x) + +print_crt(crt) + +print('res1:', res1) +print('res2:', res2) + diff --git a/2022/day10/pzl.txt b/2022/day10/pzl.txt new file mode 100644 index 0000000..540f82a --- /dev/null +++ b/2022/day10/pzl.txt @@ -0,0 +1,145 @@ +addx 1 +noop +noop +addx 4 +addx 5 +addx -2 +addx 19 +addx -12 +addx 3 +addx -2 +addx 4 +noop +noop +noop +addx 3 +addx -8 +addx 15 +addx 1 +noop +noop +addx 6 +addx -1 +noop +addx -38 +noop +addx 10 +addx -5 +noop +addx 3 +addx 2 +addx 7 +noop +noop +addx 3 +noop +addx 2 +addx 3 +addx -2 +addx 2 +addx 7 +noop +noop +addx 9 +noop +addx -12 +noop +addx 11 +addx -38 +noop +noop +noop +addx 5 +addx 5 +noop +noop +noop +addx 3 +addx -12 +addx 14 +noop +addx 1 +addx 3 +addx 1 +addx 5 +addx 4 +addx 1 +noop +noop +noop +noop +noop +addx -9 +addx 17 +addx -39 +addx 38 +addx -8 +addx -26 +addx 3 +addx 4 +addx 16 +noop +addx -11 +addx 3 +noop +addx 2 +addx 3 +addx -2 +addx 2 +noop +addx 13 +addx -8 +noop +addx 7 +addx -5 +addx 8 +addx -40 +addx 16 +addx -9 +noop +addx -7 +addx 8 +addx 2 +addx 7 +noop +noop +addx -15 +addx 16 +addx 2 +addx 5 +addx 2 +addx -20 +addx 12 +addx 11 +addx 8 +addx -1 +addx 3 +noop +addx -39 +addx 2 +noop +addx 5 +noop +noop +noop +addx 4 +addx 1 +noop +noop +addx 2 +addx 5 +addx 2 +addx 1 +addx 4 +addx -1 +addx 2 +noop +addx 2 +noop +addx 8 +noop +noop +noop +addx -10 +noop +noop diff --git a/2022/day10/ref.txt b/2022/day10/ref.txt new file mode 100644 index 0000000..37ee8ee --- /dev/null +++ b/2022/day10/ref.txt @@ -0,0 +1,146 @@ +addx 15 +addx -11 +addx 6 +addx -3 +addx 5 +addx -1 +addx -8 +addx 13 +addx 4 +noop +addx -1 +addx 5 +addx -1 +addx 5 +addx -1 +addx 5 +addx -1 +addx 5 +addx -1 +addx -35 +addx 1 +addx 24 +addx -19 +addx 1 +addx 16 +addx -11 +noop +noop +addx 21 +addx -15 +noop +noop +addx -3 +addx 9 +addx 1 +addx -3 +addx 8 +addx 1 +addx 5 +noop +noop +noop +noop +noop +addx -36 +noop +addx 1 +addx 7 +noop +noop +noop +addx 2 +addx 6 +noop +noop +noop +noop +noop +addx 1 +noop +noop +addx 7 +addx 1 +noop +addx -13 +addx 13 +addx 7 +noop +addx 1 +addx -33 +noop +noop +noop +addx 2 +noop +noop +noop +addx 8 +noop +addx -1 +addx 2 +addx 1 +noop +addx 17 +addx -9 +addx 1 +addx 1 +addx -3 +addx 11 +noop +noop +addx 1 +noop +addx 1 +noop +noop +addx -13 +addx -19 +addx 1 +addx 3 +addx 26 +addx -30 +addx 12 +addx -1 +addx 3 +addx 1 +noop +noop +noop +addx -9 +addx 18 +addx 1 +addx 2 +noop +noop +addx 9 +noop +noop +noop +addx -1 +addx 2 +addx -37 +addx 1 +addx 3 +noop +addx 15 +addx -21 +addx 22 +addx -6 +addx 1 +noop +addx 2 +addx 1 +noop +addx -10 +noop +noop +addx 20 +addx 1 +addx 2 +addx 2 +addx -6 +addx -11 +noop +noop +noop |
