Roderic Day vor 3 Jahren
Ursprung
Commit
0070ffd0c3
1 geänderte Dateien mit 24 neuen und 0 gelöschten Zeilen
  1. +24
    -0
      y2021/p25.py

+ 24
- 0
y2021/p25.py Datei anzeigen

@@ -0,0 +1,24 @@
text = open(0).read()
state = {}
for y, row in enumerate(text.splitlines()):
for x, ch in enumerate(row):
state[x, y] = ch
X, Y = x + 1, y + 1

seen = set()
for turn in range(1000):
for ch, dx, dy in [('>', 1, 0), ('v', 0, 1)]:
copy = state.copy()
for old in copy:
if copy[old] == ch:
x, y = old
new = (x + dx) % X, (y + dy) % Y
if copy[new] == '.':
state[old] = '.'
state[new] = ch

hashable = frozenset(state.items())
if hashable in seen:
print(turn)
break
seen.add(hashable)

Laden…
Abbrechen
Speichern