day 12 p2
This commit is contained in:
20
12/l.py
20
12/l.py
@@ -23,8 +23,6 @@ for Y, y in enumerate(input):
|
||||
cur.append(h)
|
||||
terrain.append(cur)
|
||||
|
||||
print("start:", start, "end:", end)
|
||||
|
||||
H = len(terrain)
|
||||
W = len(terrain[0])
|
||||
|
||||
@@ -41,13 +39,21 @@ def find_path(coords):
|
||||
return paths
|
||||
|
||||
|
||||
def solve():
|
||||
def solve(p):
|
||||
Q = deque()
|
||||
Q.append((start, 0))
|
||||
|
||||
if (p == 2):
|
||||
for y in range(H):
|
||||
for x in range(W):
|
||||
if terrain[y][x] == 1:
|
||||
Q.append(((y, x), 0))
|
||||
else:
|
||||
Q.append((start, 0))
|
||||
|
||||
V = set()
|
||||
|
||||
while Q:
|
||||
cur_pos, d = Q.popleft()
|
||||
print(cur_pos, d)
|
||||
if cur_pos in V:
|
||||
continue
|
||||
V.add(cur_pos)
|
||||
@@ -60,5 +66,5 @@ def solve():
|
||||
Q.append((node, d+1))
|
||||
|
||||
|
||||
print(solve())
|
||||
# print(terrain)
|
||||
print(solve(1))
|
||||
print(solve(2))
|
||||
|
||||
Reference in New Issue
Block a user