From b7d6046fc1bfdaf2261c27ab514e75186064a6f7 Mon Sep 17 00:00:00 2001 From: FrederikBaerentsen Date: Mon, 11 Dec 2023 21:19:18 +0100 Subject: [PATCH] Finished 2023-12-10 p2 --- 2023/day10/part2.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/2023/day10/part2.py b/2023/day10/part2.py index 2f66e84..3899e8a 100644 --- a/2023/day10/part2.py +++ b/2023/day10/part2.py @@ -56,6 +56,7 @@ found = False start = start_coords(grid) cur = start prev = cur +steps.append(start) count = 0 def wall(loc): @@ -185,10 +186,16 @@ while not found: p(grid,steps,inside) print(count) print(count/2) + + +# shapely doesn't give the right answer +""" polygon = Polygon(steps) for ydx,y in enumerate(grid): for xdx,x in enumerate(y): + if (ydx,xdx) in steps: + continue if polygon.contains(Point(ydx,xdx)): inside.append((ydx,xdx)) if len(sys.argv) == 4: @@ -197,3 +204,28 @@ for ydx,y in enumerate(grid): if len(sys.argv) == 2: p(grid,steps,inside) print(len(inside)) +""" + +# but Mathplotlib does + +from matplotlib.path import Path +inside = [] +print(steps) + +path = Path(steps) + +for ydx,y in enumerate(grid): + for xdx,x in enumerate(y): + if (ydx,xdx) in steps: + continue + if path.contains_point((ydx,xdx)): + inside.append((ydx,xdx)) + if len(sys.argv) == 4: + p(grid,steps,inside,xdx,ydx) + time.sleep(float(sys.argv[3])) +if len(sys.argv) == 2: + p(grid,steps,inside) +print(len(inside)) + + +