-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday18.py
executable file
·28 lines (24 loc) · 897 Bytes
/
day18.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
puzzle_input = '^^^^......^...^..^....^^^.^^^.^.^^^^^^..^...^^...^^^.^^....^..^^^.^.^^...^.^...^^.^^^.^^^^.^^.^..^.^'
def next_row(prev):
new = []
prev = '-' + prev + '-'
for i in range(1,len(prev) - 1):
if prev[i-1] == '^' and prev[i] == '^' and prev[i+1] != '^':
new.append('^')
elif prev[i+1] == '^' and prev[i] == '^' and prev[i-1] != '^':
new.append('^')
elif prev[i-1] == '^' and prev[i] != '^' and prev[i+1] != '^':
new.append('^')
elif prev[i-1] != '^' and prev[i] != '^' and prev[i+1] == '^':
new.append('^')
else:
new.append('.')
return ''.join(new)
test = '..^^.'
def room(tiles, length):
safe = 0
for row in range(length):
safe += tiles.count('.')
tiles = next_row(tiles)
print(safe)
room(puzzle_input, 400000)