diff --git a/day16/input b/day16/input new file mode 100644 index 0000000..949deb7 --- /dev/null +++ b/day16/input @@ -0,0 +1,56 @@ +Valve JI has flow rate=21; tunnels lead to valves WI, XG +Valve DM has flow rate=3; tunnels lead to valves JX, NG, AW, BY, PF +Valve AZ has flow rate=0; tunnels lead to valves FJ, VC +Valve YQ has flow rate=0; tunnels lead to valves TE, OP +Valve WI has flow rate=0; tunnels lead to valves JI, VC +Valve NE has flow rate=0; tunnels lead to valves ZK, AA +Valve FM has flow rate=0; tunnels lead to valves LC, DU +Valve QI has flow rate=0; tunnels lead to valves TE, JW +Valve OY has flow rate=0; tunnels lead to valves XS, VF +Valve XS has flow rate=18; tunnels lead to valves RR, OY, SV, NQ +Valve NU has flow rate=0; tunnels lead to valves IZ, BD +Valve JX has flow rate=0; tunnels lead to valves DM, ZK +Valve WT has flow rate=23; tunnels lead to valves OV, QJ +Valve KM has flow rate=0; tunnels lead to valves TE, OL +Valve NG has flow rate=0; tunnels lead to valves II, DM +Valve FJ has flow rate=0; tunnels lead to valves AZ, II +Valve QR has flow rate=0; tunnels lead to valves ZK, KI +Valve KI has flow rate=9; tunnels lead to valves ZZ, DI, TL, AJ, QR +Valve ON has flow rate=0; tunnels lead to valves LC, QT +Valve AW has flow rate=0; tunnels lead to valves DM, AA +Valve HI has flow rate=0; tunnels lead to valves TE, VC +Valve XG has flow rate=0; tunnels lead to valves II, JI +Valve II has flow rate=19; tunnels lead to valves LF, NG, OL, FJ, XG +Valve VC has flow rate=24; tunnels lead to valves WI, HI, AZ +Valve VJ has flow rate=0; tunnels lead to valves UG, AA +Valve IZ has flow rate=0; tunnels lead to valves VF, NU +Valve EJ has flow rate=0; tunnels lead to valves ZK, LC +Valve DU has flow rate=12; tunnels lead to valves TC, UG, FM +Valve ZK has flow rate=10; tunnels lead to valves JX, EJ, JW, QR, NE +Valve XF has flow rate=25; tunnels lead to valves OP, VT +Valve LC has flow rate=4; tunnels lead to valves FM, EJ, ON, AJ, PF +Valve SV has flow rate=0; tunnels lead to valves XS, IY +Valve LF has flow rate=0; tunnels lead to valves II, OV +Valve DI has flow rate=0; tunnels lead to valves KI, BY +Valve OP has flow rate=0; tunnels lead to valves YQ, XF +Valve NQ has flow rate=0; tunnels lead to valves TC, XS +Valve QJ has flow rate=0; tunnels lead to valves VT, WT +Valve IY has flow rate=22; tunnel leads to valve SV +Valve AJ has flow rate=0; tunnels lead to valves LC, KI +Valve TE has flow rate=11; tunnels lead to valves QI, HI, KM, YQ +Valve ZZ has flow rate=0; tunnels lead to valves KI, AA +Valve VT has flow rate=0; tunnels lead to valves XF, QJ +Valve OL has flow rate=0; tunnels lead to valves KM, II +Valve TC has flow rate=0; tunnels lead to valves NQ, DU +Valve TL has flow rate=0; tunnels lead to valves VF, KI +Valve QT has flow rate=0; tunnels lead to valves AA, ON +Valve BY has flow rate=0; tunnels lead to valves DM, DI +Valve OV has flow rate=0; tunnels lead to valves LF, WT +Valve VN has flow rate=0; tunnels lead to valves RR, BD +Valve VF has flow rate=13; tunnels lead to valves OY, IZ, TL +Valve BD has flow rate=17; tunnels lead to valves NU, VN +Valve UG has flow rate=0; tunnels lead to valves VJ, DU +Valve PF has flow rate=0; tunnels lead to valves LC, DM +Valve RR has flow rate=0; tunnels lead to valves XS, VN +Valve AA has flow rate=0; tunnels lead to valves QT, ZZ, AW, VJ, NE +Valve JW has flow rate=0; tunnels lead to valves ZK, QI diff --git a/day16/sol.py b/day16/sol.py new file mode 100644 index 0000000..d5aa014 --- /dev/null +++ b/day16/sol.py @@ -0,0 +1,49 @@ +G = [] +for line in open("input"): + words = line.split() + valve = words[1] + rate = words[4] + edges = [x.strip(", ") for x in words[9:]] + + print(rate) + rate = rate.strip(";") + rate = rate[rate.index("=")+1:] + rate = int(rate) + G.append((valve, rate, edges)) + +print(G) + +#import astar + +score = {'AA': (0, frozenset())} + +#E = {x[0]: x[2] for x in G} +#assert all(v in E[e] for v in E for e in E[v]) + +# find the largest reward we can get in n steps +# then find the largest reward we can get in n+1 steps +minutes = 30 +for _ in range(30): + minutes -= 1 + next = {} + for v, r, E in G: + s = set() + if v in score: + reward, open = score[v] + # stay, don't open valve + s.add((reward, open)) + # stay in place, open valve + if v not in open: + reward += r*minutes + open = open.union(frozenset([v])) + s.add((reward, open)) + # move here from somewhere else + for e in E: + if e in score: + s.add(score[e]) + if s: + reward, open = max(s) + next[v] = (reward,open) + score = next + print(score) +print(max(r for r,_ in score.values()))