/ Python / 2022 / 10.py
10.py
 1  from lib import *
 2  
 3  input = read_input(2022, 10)
 4  
 5  instructions = [next(iter(ints(line)), None) for line in input.splitlines()]
 6  
 7  
 8  def execute():
 9      x = 1
10      i = 0
11      for inst in instructions:
12          yield i, x
13          i += 1
14          if inst is not None:
15              yield i, x
16              i += 1
17              x += inst
18  
19  
20  print(sum((i + 1) * x for i, x in execute() if i % 40 == 19))
21  print(parse_ascii({(i // 40, i % 40) for i, x in execute() if abs(i % 40 - x) <= 1}))