day 9 cheated kinda :c

This commit is contained in:
Aéna Aria 2025-12-09 14:28:13 +01:00
parent 8d7b9d1971
commit 1931c20b69
2 changed files with 83 additions and 27 deletions

34
day9/2cheat.py Normal file
View file

@ -0,0 +1,34 @@
import shapely
from shapely.geometry import Point, Polygon
with open(r'day9/input.txt', 'r') as input:
lines = list(map(lambda x: list(map(lambda y: int(y),x.split(','))),input.read().split('\n')[:-1]))
points = []
def surface(a,b):
return (abs(a.x-b.x)+1)*(abs(a.y-b.y)+1)
for line in lines:
points.append(Point(line[0],line[1]))
points.append(points[0])
polygon = Polygon([p.x,p.y] for p in points)
bestarea = shapely.area(shapely.box(0,0,0,0))
for i in range(len(points)):
print(i)
for j in range(i):
minx = min(points[i].x,points[j].x)
miny = min(points[i].y,points[j].y)
maxx = max(points[i].x,points[j].x)
maxy = max(points[i].y,points[j].y)
box = shapely.box(minx,miny,maxx,maxy)
box_surface = surface(points[i],points[j])
if box_surface > bestarea and shapely.contains(polygon,box):
bestarea = box_surface
print(bestarea)