day 22 part 2

main
magical 2023-12-22 06:47:19 +00:00
parent 2635e69315
commit efd7f887b8
1 changed files with 39 additions and 1 deletions

View File

@ -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"""