20 lines
505 B
Python
Executable File
20 lines
505 B
Python
Executable File
#!/usr/bin/env python3
|
|
import sys
|
|
from collections import defaultdict
|
|
data = [l.strip() for l in sys.stdin.readlines()]
|
|
grid = defaultdict(bool)
|
|
for i, row in enumerate(data):
|
|
for j, col in enumerate(row):
|
|
grid[complex(j, i)] = (col == "#")
|
|
pos, d = complex(len(data) // 2, len(data[0]) // 2), 1j
|
|
becomeinfected = 0
|
|
for _ in range(10000):
|
|
if grid[pos]:
|
|
d *= 1j
|
|
else:
|
|
d *= -1j
|
|
becomeinfected += 1
|
|
grid[pos] = not grid[pos]
|
|
pos += d
|
|
print(becomeinfected)
|