oof
This commit is contained in:
parent
3e822d7f55
commit
1414bb26e7
BIN
2022/python/15.png
Normal file
BIN
2022/python/15.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 35 KiB |
|
@ -43,11 +43,11 @@ def parse(rows):
|
||||||
|
|
||||||
|
|
||||||
def part1(rows, sample=False):
|
def part1(rows, sample=False):
|
||||||
p1 = Part1(rows, sample, 30)
|
p1 = Volcano(rows, sample, 30)
|
||||||
p1.run()
|
p1.run()
|
||||||
|
|
||||||
|
|
||||||
class Part1:
|
class Volcano:
|
||||||
def __init__(self, rows, sample, minutes):
|
def __init__(self, rows, sample, minutes):
|
||||||
self.rows = rows
|
self.rows = rows
|
||||||
self.sample = sample
|
self.sample = sample
|
||||||
|
@ -78,9 +78,7 @@ class Part1:
|
||||||
if other == lbl:
|
if other == lbl:
|
||||||
continue
|
continue
|
||||||
self.path_distances[lbl][other] = l[lbl][other]
|
self.path_distances[lbl][other] = l[lbl][other]
|
||||||
# min(
|
self.draw()
|
||||||
# [len(x) for x in nx.shortest_simple_paths(self.g, lbl, other)]
|
|
||||||
# )
|
|
||||||
|
|
||||||
def do_tick(self, minute):
|
def do_tick(self, minute):
|
||||||
pressure = 0
|
pressure = 0
|
||||||
|
@ -120,7 +118,6 @@ class Part1:
|
||||||
pprint(_pris)
|
pprint(_pris)
|
||||||
return _pris
|
return _pris
|
||||||
|
|
||||||
|
|
||||||
remaining = self.minutes
|
remaining = self.minutes
|
||||||
open_order = []
|
open_order = []
|
||||||
while len(self.nonzero):
|
while len(self.nonzero):
|
||||||
|
@ -141,15 +138,14 @@ class Part1:
|
||||||
del self.nonzero[nxt]
|
del self.nonzero[nxt]
|
||||||
# keep track of which order opened
|
# keep track of which order opened
|
||||||
open_order.append(n.label)
|
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.cur = n.label
|
||||||
self.valves[self.cur].opened_at = self.minutes - (remaining - 1)
|
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
|
remaining -= distance # Move
|
||||||
print("\t\tMoved", distance,"distance/minutes")
|
print("\t\tMoved", distance,"distance/minutes")
|
||||||
remaining -= 1 # open
|
remaining -= 1 # open
|
||||||
|
@ -164,6 +160,9 @@ class Part1:
|
||||||
print("total flow:", self.calculate_total_flow())
|
print("total flow:", self.calculate_total_flow())
|
||||||
|
|
||||||
|
|
||||||
|
def part2(rows, sample=False):
|
||||||
|
p2 = Volcano(rows, sample, 26)
|
||||||
|
p2.run()
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
sample = False
|
sample = False
|
||||||
|
|
Loading…
Reference in New Issue
Block a user