summaryrefslogtreecommitdiffstats
path: root/problem10.py
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@gmail.com>2023-01-04 21:46:23 -0500
committerGuillaume Horel <guillaume.horel@gmail.com>2023-01-04 21:46:23 -0500
commit6373305f20fdbb47cb6f676cf462374e043dedf6 (patch)
treea022bb2fbfebd2ace7ce15a4d82d0b77403a9572 /problem10.py
download2022-6373305f20fdbb47cb6f676cf462374e043dedf6.tar.gz
initial importHEADmaster
Diffstat (limited to 'problem10.py')
-rw-r--r--problem10.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/problem10.py b/problem10.py
new file mode 100644
index 0000000..41ce1eb
--- /dev/null
+++ b/problem10.py
@@ -0,0 +1,38 @@
+from common import day
+
+fh = open(f"input/{day()}")
+X = 1
+cycle = 0
+r = 0
+row = []
+while True:
+ cycle += 1
+ pos = (cycle - 1) % 40
+ if pos == 0:
+ print("".join(row))
+ row = []
+ if pos in (X-1, X, X+1):
+ row.append("#")
+ else:
+ row.append(".")
+ try:
+ line = next(fh)
+ except StopIteration:
+ print(r)
+ break
+ line = line.rstrip()
+ match line.split():
+ case ["noop"]:
+ continue
+ case ["addx", val]:
+ val = int(val)
+ cycle += 1
+ pos = (cycle - 1) % 40
+ if pos == 0:
+ print("".join(row))
+ row = []
+ if pos in (X-1, X, X+1):
+ row.append("#")
+ else:
+ row.append(".")
+ X += val