From 80cf54d60095a095690e61ebb21ac3fb9cb9373a Mon Sep 17 00:00:00 2001 From: Andrew Ekstedt Date: Tue, 13 Dec 2022 22:18:59 -0800 Subject: [PATCH] day 14 python optimize --- day14/sol.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/day14/sol.py b/day14/sol.py index aff40a0..ae2d482 100644 --- a/day14/sol.py +++ b/day14/sol.py @@ -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'