day 14 python optimize

main
magical 2022-12-13 22:18:59 -08:00
parent 99fa431441
commit 80cf54d600
1 changed files with 6 additions and 1 deletions

View File

@ -65,11 +65,15 @@ def show():
show()
def drip(p, floor=None):
def drip(p, floor=None, lastpath=[]):
x,y=p
if p in lastpath:
x,y = lastpath.pop()
while True:
lastpath.append((x,y))
if y+1 == floor:
# blocked
lastpath.pop()
put(x,y,'o')
return 'done'
if y >= Y1:
@ -89,6 +93,7 @@ def drip(p, floor=None):
x,y = x+1, y+1
continue
# blocked!
lastpath.pop()
put(x,y,'o')
#print(x,y)
return 'done'