Skip to content

Commit 1e7805f

Browse files
committed
Add day09, 2025
1 parent c9523cf commit 1e7805f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

2025/day09/solution.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from itertools import combinations
2+
from shapely.geometry.polygon import Polygon, LineString
3+
4+
with open("input") as f:
5+
inp = f.read().strip().split("\n")
6+
7+
coords = [(x, y) for x, y in (map(int, line.split(",")) for line in inp)]
8+
9+
# Part 1
10+
print(
11+
max(
12+
(abs(x1 - x2) + 1) * (abs(y1 - y2) + 1)
13+
for (x1, y1), (x2, y2) in combinations(coords, 2)
14+
)
15+
)
16+
17+
# Part 2
18+
polygon = Polygon(coords)
19+
ans = 0
20+
21+
for (x1, y1), (x2, y2) in combinations(coords, 2):
22+
p1 = (x1, y1)
23+
p2 = (x2, y2)
24+
p3 = (x1, y2)
25+
p4 = (x2, y1)
26+
lines = [LineString([p1, p3]), LineString([p1, p4]), LineString([p3, p2]), LineString([p2, p4])]
27+
if all(line.covered_by(polygon) for line in lines):
28+
ans = max(ans, (abs(x1 - x2) + 1)*(abs(y1 - y2) + 1))
29+
30+
print(ans)

0 commit comments

Comments
 (0)