-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path18-2.py
50 lines (36 loc) · 807 Bytes
/
18-2.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/python3.5
import sys
import re
from pprint import pprint
#from operator import itemgetter
tiles = []
while True:
try:
line = sys.stdin.readline().rstrip()
except KeyboardInterrupt:
break
if not line:
break
tiles = [ c == '.' for c in line]
print(tiles)
def trap(x,a):
if a==0:
l=True
else:
l=x[a-1]
if a==len(x)-1:
r=True
else:
r=x[a+1]
return not(l != r)
rows = 400000
total = tiles.count(True)
for i in range(1,rows):
newtiles = []
for j in range(len(tiles)):
newtiles.append(trap(tiles, j))
tiles = newtiles
total += tiles.count(True)
#pprint([''.join(['.' if c else '^' for c in row ]) for row in tiles])
#print(sum([x.count(True) for x in tiles]))
print(total)