2023/day10/part2.py
Fedaya 64a270ee39 Day 10 completed
completed with the help of shapely python module

other minors changes in day5
2023-12-10 17:34:02 +01:00

28 lines
735 B
Python
Executable File

#!/usr/bin/env python3.11
from common import *
import shapely
def inside_points(labyrinth: Labyrinth) -> list[Point]:
labyrinth = labyrinth.clean()
path = labyrinth.get_path()
empty_points = labyrinth.get_empty_points()
logging.debug("let's shapely that")
shp_path = []
for point in path:
shp_path.append(shapely.Point(point.x, point.y))
polygon = shapely.Polygon(shp_path)
inside_points = []
for point in empty_points:
current = shapely.Point(point.x, point.y)
if shapely.contains(polygon, current):
inside_points.append(point)
return inside_points
if __name__ == "__main__":
labyrinth = parse("input.txt")
print(len(inside_points(labyrinth)))