123456789101112131415161718192021222324252627282930313233343536373839404142 |
- lines = [line.strip().split() for line in open("10.input")]
- X = 1
- cycle = 0
- snap_times = [20, 60, 100, 140, 180, 220]
- snaps = []
- pixels = []
- def run_cycle():
- global cycle, snap_times, snaps, pixels, X
- cycle += 1
- if cycle in snap_times:
- snaps.append(X)
- col = (cycle - 1) % 40
- if abs(col - X) <= 1:
- pixels.append("█")
- else:
- pixels.append(" ")
- for line in lines:
- if len(line) == 1:
- run_cycle()
- else:
- run_cycle()
- run_cycle()
- X += int(line[1])
- # Part 1
- prod = [a * b for a, b in zip(snaps, snap_times)]
- print(sum(prod))
- # Part 2
- for row in range(0, 6):
- for pos in range(row*40, (row+1)*40):
- print(pixels[pos], end='')
- print("")
|