This commit is contained in:
Tyrel Souza 2022-12-17 11:54:31 -05:00
parent 3e822d7f55
commit 1414bb26e7
2 changed files with 10 additions and 11 deletions

BIN
2022/python/15.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

View File

@ -43,11 +43,11 @@ def parse(rows):
def part1(rows, sample=False):
p1 = Part1(rows, sample, 30)
p1 = Volcano(rows, sample, 30)
p1.run()
class Part1:
class Volcano:
def __init__(self, rows, sample, minutes):
self.rows = rows
self.sample = sample
@ -78,9 +78,7 @@ class Part1:
if other == lbl:
continue
self.path_distances[lbl][other] = l[lbl][other]
# min(
# [len(x) for x in nx.shortest_simple_paths(self.g, lbl, other)]
# )
self.draw()
def do_tick(self, minute):
pressure = 0
@ -120,7 +118,6 @@ class Part1:
pprint(_pris)
return _pris
remaining = self.minutes
open_order = []
while len(self.nonzero):
@ -142,14 +139,13 @@ class Part1:
# keep track of which order opened
open_order.append(n.label)
print("\tMoving to", nxt)
print("\tOpening", n.label)
#distance = self.path_distances[self.cur][n.label]
self.cur = n.label
self.valves[self.cur].opened_at = self.minutes - (remaining - 1)
self.do_tick(self.minutes+1-remaining)
print("\tMoving to", n.label)
print("\tOpening ", n.label)
print()
# Tick tick tick
remaining -= distance # Move
print("\t\tMoved", distance,"distance/minutes")
remaining -= 1 # open
@ -164,6 +160,9 @@ class Part1:
print("total flow:", self.calculate_total_flow())
def part2(rows, sample=False):
p2 = Volcano(rows, sample, 26)
p2.run()
def main():
sample = False