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.

36 lines
814B

  1. """
  2. 5000 steps, he can reach 16733044 garden plots.
  3. 26501365?
  4. """
  5. text = open(0).read()
  6. graph = {
  7. complex(x, y): val
  8. for y, row in enumerate(text.splitlines())
  9. for x, val in enumerate(row)
  10. }
  11. width = max(int(p.real) for p in graph) + 1
  12. height = max(int(p.imag) for p in graph) + 1
  13. block = lambda p: complex(p.real // width, p.imag // height)
  14. wrap = lambda p: complex(p.real % width, p.imag % height)
  15. start, = (k for k, v in graph.items() if v == 'S')
  16. seen = [set(), set()]
  17. state = {start}
  18. bops = set()
  19. for step in range(130):
  20. twinkle = seen[step % 2]
  21. twinkle |= state
  22. if step == 64:
  23. print(len(twinkle)) # ans1
  24. state = {
  25. p + s
  26. for p in state
  27. for s in [1, -1, 1j, -1j]
  28. if graph[wrap(p + s)] in {'.', 'S'}
  29. if p + s not in twinkle
  30. }