Skip to content

Commit 52aea43

Browse files
committed
Day 10
1 parent f0a4e94 commit 52aea43

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
|[Day 7: No Space Left On Device](https://adventofcode.com/2022/day/7) |[py](/day07/main.py), [alt](/day07/alt.py)|
1212
|[Day 8: Treetop Tree House](https://adventofcode.com/2022/day/8) |[py](/day08/main.py)|
1313
|[Day 9: Rope Bridge](https://adventofcode.com/2022/day/9) |[py](/day09/main.py)|
14+
|[Day 10: Cathode-Ray Tube](https://adventofcode.com/2022/day/10) |[py](/day10/main.py)|
1415

1516
My solutions from previous years:
1617
* [r0f1/adventofcode2020](https://github.com/r0f1/adventofcode2020)

day10/main.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
instructions = open("input.txt").readlines()
2+
3+
x = 1
4+
c = 0
5+
hist = [x]
6+
output = ""
7+
8+
pix = lambda c, x: "#" if abs(c - x) <= 1 else "."
9+
10+
for instr in instructions:
11+
output += pix(c, x)
12+
c = (c + 1) % 40
13+
if instr.startswith("addx"):
14+
output += pix(c, x)
15+
c = (c + 1) % 40
16+
hist.append(x)
17+
x += int(instr.split()[1])
18+
hist.append(x)
19+
20+
print(sum(i*hist[i-1] for i in range(20, 221, 40)))
21+
for row in range(0, 6):
22+
print(output[row*40:(row+1)*40])

0 commit comments

Comments
 (0)