Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

25 linhas
679B

  1. def condition(x, y, on):
  2. is_on = (x, y) in on
  3. neighbours_on = sum(
  4. (x + dx, y + dy) in on
  5. for dx in [1, 0, -1] for dy in [1, 0, -1]
  6. if dx or dy
  7. )
  8. return (is_on and neighbours_on in {2, 3}) or neighbours_on == 3
  9. on1 = {
  10. (x, y)
  11. for y, ln in enumerate(df.read_text().splitlines())
  12. for x, ch in enumerate(ln)
  13. if ch == '#'
  14. }
  15. on2 = set(on1)
  16. grid = {(x, y) for x in range(100) for y in range(100)}
  17. corners = {(0, 0), (0, 99), (99, 0), (99, 99)}
  18. for _ in range(100):
  19. on1 = {(x, y) for x, y in grid if condition(x, y, on1)}
  20. on2 = {(x, y) for x, y in grid if condition(x, y, on2)} | corners
  21. ans1 = len(on1)
  22. ans2 = len(on2)