day 22 part 2
parent
2635e69315
commit
efd7f887b8
40
day22/sol.py
40
day22/sol.py
|
@ -38,7 +38,8 @@ def solve(f):
|
|||
check(data)
|
||||
settle(data)
|
||||
check(data)
|
||||
disintegrate(data)
|
||||
#disintegrate(data)
|
||||
cascade(data)
|
||||
|
||||
def settle(data):
|
||||
def zindex(b):
|
||||
|
@ -118,6 +119,43 @@ def disintegrate(data):
|
|||
return (t)
|
||||
|
||||
|
||||
def cascade(data):
|
||||
print(*data, sep="\n")
|
||||
t = 0
|
||||
|
||||
#for i,x in enumerate(data):
|
||||
# assert not canlower(x,data[:i])
|
||||
|
||||
for i,x in enumerate(data):
|
||||
below = data[:i]
|
||||
upper = data[i+1:]
|
||||
moved = 0
|
||||
|
||||
if below:
|
||||
top = max(z[1] for x,y,z in below) + 1
|
||||
else:
|
||||
top = 1
|
||||
for b in upper:
|
||||
# lower blocks one at a time
|
||||
z = b[2][0]
|
||||
if z > top:
|
||||
b = lower(b, z-top)
|
||||
|
||||
while canlower(b, below):
|
||||
b = lower(b)
|
||||
|
||||
if b[2][0] < z:
|
||||
moved += 1
|
||||
|
||||
#print("lowering block %d by %d" % (i,n))
|
||||
below.append(b)
|
||||
top = max(top, b[2][1]+1)
|
||||
|
||||
print(i, x, "caused %d blocks to move" % moved)
|
||||
t += moved
|
||||
|
||||
print(t)
|
||||
return (t)
|
||||
|
||||
def lower(brick, n=1):
|
||||
"""lower a brick n spaces in the z direction"""
|
||||
|
|
Loading…
Reference in New Issue