summaryrefslogtreecommitdiffstats
path: root/10.py
diff options
context:
space:
mode:
authorTomasz Kramkowski <tomasz@kramkow.ski>2022-12-10 12:32:32 +0000
committerTomasz Kramkowski <tomasz@kramkow.ski>2022-12-10 12:32:32 +0000
commit803e8d3e3812f72471c35d90a25b86d05263ed83 (patch)
tree875e7e98893b817af515d5ed0a8a378de409fa0a /10.py
parentd9a97e9bf28cf91f1a7e57f1298b7c742e25ed56 (diff)
downloadaoc2022-803e8d3e3812f72471c35d90a25b86d05263ed83.tar.gz
aoc2022-803e8d3e3812f72471c35d90a25b86d05263ed83.tar.xz
aoc2022-803e8d3e3812f72471c35d90a25b86d05263ed83.zip
8, 10
Diffstat (limited to '10.py')
-rw-r--r--10.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/10.py b/10.py
new file mode 100644
index 0000000..27dbde9
--- /dev/null
+++ b/10.py
@@ -0,0 +1,42 @@
+from dataclasses import dataclass
+
+@dataclass
+class Cycle:
+ pass
+
+@dataclass
+class Change:
+ diff: int
+
+instrs = []
+with open('10.in') as f:
+ for line in f:
+ match line.rstrip().split():
+ case ['addx', n]:
+ instrs.append(Cycle())
+ instrs.append(Cycle())
+ instrs.append(Change(int(n)))
+ case ['noop']:
+ instrs.append(Cycle())
+
+cycle = 0
+sigstr = 0
+X = 1
+screen = [0 for _ in range(240)]
+for instr in instrs:
+ match instr:
+ case Cycle():
+ cycle += 1
+ if (cycle - 20) % 40 == 0:
+ sigstr += cycle * X
+ xpos = (cycle - 1) % 40
+ if xpos - 1 <= X <= xpos + 1:
+ screen[cycle - 1] = 1
+ case Change(diff):
+ X += diff
+print(sigstr)
+for y in range(6):
+ line = []
+ for x in range(40):
+ line.append('#' if screen[x + 40 * y] else ' ')
+ print(''.join(line))