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