You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
485B

  1. text = open(0).read()
  2. cycles = [1]
  3. for ln in map(str.split, text.splitlines()):
  4. match ln:
  5. case ['addx', i]:
  6. cycles.extend([0, int(i)])
  7. case ['noop']:
  8. cycles.extend([0])
  9. ans1 = 0
  10. ans2, W, H = '', 40, 6
  11. for y in range(H):
  12. for x in range(W):
  13. i = 1 + y * W + x
  14. p = sum(cycles[:i])
  15. if i % 40 == 20:
  16. ans1 += i * p
  17. ans2 += '##' if abs(x - p) <= 1 else ' '
  18. ans2 += '\n'
  19. print(ans1)
  20. print(ans2)