Skip to content

Commit 9a5f1da

Browse files
committed
more
1 parent b813c75 commit 9a5f1da

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

20.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def p_pattern(t):
1717
'pattern : concat'
1818
t[0] = t[1]
1919

20-
def p_pattern_concat(t):
20+
def p_pattern_or(t):
2121
'pattern : pattern OR concat'
2222
t[0] = ('or', t[1], t[3])
2323

@@ -91,14 +91,18 @@ def show(doors):
9191
for y in range(y0, y1 + 1):
9292
row1, row2 = ['#'], ['#']
9393
for x in range(x0 , x1 + 1):
94-
row1.append('X' if x == 0 and y == 0 else '.')
95-
row1.append('|' if (x, y, x + 1, y) in doors else '#')
96-
row2.append('-#' if (x, y, x, y + 1) in doors else '##')
94+
has_door = any((x, y, x + dx, y + dy) in doors
95+
for dx, dy in dirs.values())
96+
c = '.' if has_door else '#'
97+
row1.append('X' if x == 0 and y == 0 else c)
98+
row1.append('.' if (x, y, x + 1, y) in doors else '#')
99+
row2.append('.#' if (x, y, x, y + 1) in doors else '##')
97100
rows.append(''.join(row1))
98101
rows.append(''.join(row2))
99102
return '\n'.join(rows)
100103

101104
doors = locate_doors(next(fileinput.input()))
105+
# print(show(doors))
102106
distances = search(doors)
103107
print(max(distances.values()))
104108
print(sum(x >= 1000 for x in distances.values()))

0 commit comments

Comments
 (0)