aboutsummaryrefslogtreecommitdiff
path: root/2022/10
diff options
context:
space:
mode:
authorMarvin Borner2022-12-10 09:57:16 +0100
committerMarvin Borner2022-12-10 10:02:39 +0100
commit5179b273acc3c76b1aa56cbece86837b6d3d3427 (patch)
tree90d286049b20dc8ddaa8f05067269b9ba9160176 /2022/10
parentbd845fcd5fca3adfbd390755ee8f784ea7b64a9f (diff)
Interesting
Diffstat (limited to '2022/10')
-rw-r--r--2022/10/input145
-rw-r--r--2022/10/solve.py39
2 files changed, 184 insertions, 0 deletions
diff --git a/2022/10/input b/2022/10/input
new file mode 100644
index 0000000..540f82a
--- /dev/null
+++ b/2022/10/input
@@ -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/10/solve.py b/2022/10/solve.py
new file mode 100644
index 0000000..31c933f
--- /dev/null
+++ b/2022/10/solve.py
@@ -0,0 +1,39 @@
+data = [dat.strip().split(" ") for dat in open("input").readlines() if dat != '']
+
+def solve():
+ signal_strength = 0
+
+ crt = [["?" for j in range(40)] for i in range(6)]
+ col = row = 0
+
+ x = 1
+ cycle = timeout = i = 0
+ while i < len(data):
+ instr = data[i]
+
+ if cycle > 0 and cycle % 40 == 0:
+ col = 0
+ row += 1
+
+ cycle += 1
+
+ if cycle - 20 >= 0 and (cycle - 20) % 40 == 0:
+ signal_strength += cycle * x
+
+ crt[row][col] = "#" if col in [x-1,x,x+1] else "."
+ col += 1
+
+ if instr[0] == "noop":
+ i += 1
+ elif timeout > 0 and instr[0] == "addx":
+ timeout -= 1
+ if timeout == 0:
+ x += int(instr[1])
+ i += 1
+ elif timeout == 0 and instr[0] == "addx":
+ timeout = 1
+
+ print(f"Part 1: {signal_strength}")
+ print("\n".join(["".join(row) for row in crt]))
+
+solve()