-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path16.py
69 lines (41 loc) · 1.2 KB
/
16.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# %%
I = open("inputs22/16t").read().split("\n")
paths = {}
for line in I:
_, valve, _, _, rate, _, _, _, _, *nextvalves = line.split(" ")
nextvalves = [n.split(",")[0] for n in nextvalves]
rate = int(rate[5:-1])
print(valve, rate, nextvalves)
paths[valve] = (rate, False, nextvalves)
paths
import heapq as hq
H = []
hq.heappush(H, (0, "AA"))
data = {v:0 for v in paths.keys()}
timeleft =
# what do we care when we move to a specific valve:
# time + gas elapsed
# limited time -> make most gas escape
#
while H:
value, valve = hq.heappop(H)
rate, isopen, nextpaths = paths[valve]
if isopen:
totalrate = 0
else:
# TODO: takes 1 minute to open it
totalrate += rate
if D[coords] == inf: # not yet visited
# if D[coords] < value:
# print(1)
D[coords] = value
if coords == end:
print("DONE")
break
for neighbour in get_neighbours_of(*coords):
if D[neighbour] > (D[coords] + 1): # replace current path if shorter path exists
hq.heappush(H, (D[coords] + 1, neighbour))
# idea:
# start in
# does it make sense to keep track of the path?
# %%