Finished 2023-12-10 p2
This commit is contained in:
parent
329e2d62b1
commit
b7d6046fc1
@ -56,6 +56,7 @@ found = False
|
|||||||
start = start_coords(grid)
|
start = start_coords(grid)
|
||||||
cur = start
|
cur = start
|
||||||
prev = cur
|
prev = cur
|
||||||
|
steps.append(start)
|
||||||
count = 0
|
count = 0
|
||||||
|
|
||||||
def wall(loc):
|
def wall(loc):
|
||||||
@ -185,10 +186,16 @@ while not found:
|
|||||||
p(grid,steps,inside)
|
p(grid,steps,inside)
|
||||||
print(count)
|
print(count)
|
||||||
print(count/2)
|
print(count/2)
|
||||||
|
|
||||||
|
|
||||||
|
# shapely doesn't give the right answer
|
||||||
|
"""
|
||||||
polygon = Polygon(steps)
|
polygon = Polygon(steps)
|
||||||
|
|
||||||
for ydx,y in enumerate(grid):
|
for ydx,y in enumerate(grid):
|
||||||
for xdx,x in enumerate(y):
|
for xdx,x in enumerate(y):
|
||||||
|
if (ydx,xdx) in steps:
|
||||||
|
continue
|
||||||
if polygon.contains(Point(ydx,xdx)):
|
if polygon.contains(Point(ydx,xdx)):
|
||||||
inside.append((ydx,xdx))
|
inside.append((ydx,xdx))
|
||||||
if len(sys.argv) == 4:
|
if len(sys.argv) == 4:
|
||||||
@ -197,3 +204,28 @@ for ydx,y in enumerate(grid):
|
|||||||
if len(sys.argv) == 2:
|
if len(sys.argv) == 2:
|
||||||
p(grid,steps,inside)
|
p(grid,steps,inside)
|
||||||
print(len(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))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user