day 14 python optimize
parent
99fa431441
commit
80cf54d600
|
@ -65,11 +65,15 @@ def show():
|
||||||
|
|
||||||
show()
|
show()
|
||||||
|
|
||||||
def drip(p, floor=None):
|
def drip(p, floor=None, lastpath=[]):
|
||||||
x,y=p
|
x,y=p
|
||||||
|
if p in lastpath:
|
||||||
|
x,y = lastpath.pop()
|
||||||
while True:
|
while True:
|
||||||
|
lastpath.append((x,y))
|
||||||
if y+1 == floor:
|
if y+1 == floor:
|
||||||
# blocked
|
# blocked
|
||||||
|
lastpath.pop()
|
||||||
put(x,y,'o')
|
put(x,y,'o')
|
||||||
return 'done'
|
return 'done'
|
||||||
if y >= Y1:
|
if y >= Y1:
|
||||||
|
@ -89,6 +93,7 @@ def drip(p, floor=None):
|
||||||
x,y = x+1, y+1
|
x,y = x+1, y+1
|
||||||
continue
|
continue
|
||||||
# blocked!
|
# blocked!
|
||||||
|
lastpath.pop()
|
||||||
put(x,y,'o')
|
put(x,y,'o')
|
||||||
#print(x,y)
|
#print(x,y)
|
||||||
return 'done'
|
return 'done'
|
||||||
|
|
Loading…
Reference in New Issue