Finished 2023-12-10 p2

This commit is contained in:
FrederikBaerentsen 2023-12-11 21:19:18 +01:00
parent 329e2d62b1
commit b7d6046fc1

View File

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