2017 day 22 part 1
This commit is contained in:
parent
47b3d9fc19
commit
336341abce
|
@ -0,0 +1,19 @@
|
|||
#!/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)
|
Loading…
Reference in New Issue