aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Voss <thomas.voss@humanwave.nl> 2025-12-09 10:49:36 +0100
committerThomas Voss <thomas.voss@humanwave.nl> 2025-12-09 10:49:36 +0100
commitaabaee2b1c625ab17ab3149d36e2042301174df9 (patch)
tree38c7e7c9e7f1f43c15d881bb71797a76e3af525c
parent4b8d68d76ed8a612aac76e591157486b52c79d0e (diff)
Add 2025 day 9 solutions
-rwxr-xr-x2025/09/puzzle-1.py29
-rwxr-xr-x2025/09/puzzle-2.py49
2 files changed, 78 insertions, 0 deletions
diff --git a/2025/09/puzzle-1.py b/2025/09/puzzle-1.py
new file mode 100755
index 0000000..6d42141
--- /dev/null
+++ b/2025/09/puzzle-1.py
@@ -0,0 +1,29 @@
+#!/usr/bin/python3
+
+import itertools
+
+
+type Point = tuple[int, int]
+
+
+def main() -> None:
+ with open('input', 'r') as f:
+ xs = [tuple(map(int, l.split(','))) for l in f.readlines()]
+
+ it = itertools.combinations(xs, 2)
+ it = itertools.starmap(area, it)
+ print(max(it))
+
+
+def area(p: Point, q: Point) -> int:
+ a, b = minmax(p[0], q[0])
+ c, d = minmax(p[1], q[1])
+ return (b - a + 1) * (d - c + 1)
+
+
+def minmax(x: int, y: int) -> tuple[int, int]:
+ return (x, y) if x < y else (y, x)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/2025/09/puzzle-2.py b/2025/09/puzzle-2.py
new file mode 100755
index 0000000..f77c4c1
--- /dev/null
+++ b/2025/09/puzzle-2.py
@@ -0,0 +1,49 @@
+#!/usr/bin/python3
+
+import itertools
+
+
+type Point = tuple[int, int]
+type Box = tuple[int, int, int, int]
+
+
+def main() -> None:
+ with open('input', 'r') as f:
+ xs = [tuple(map(int, l.split(','))) for l in f.readlines()]
+
+ it = itertools.pairwise(xs)
+ it = itertools.starmap(tobox, it)
+ ys = list(it)
+
+ n = 0
+ it = itertools.combinations(xs, 2)
+ it = itertools.starmap(tobox, it)
+ for x in it:
+ if (_area := area(x)) <= n:
+ continue
+ a, b, c, d = x
+ for p, q, r, s in ys:
+ if a < r and b < s and c > p and d > q:
+ break
+ else:
+ n = _area
+
+ print(n)
+
+
+def tobox(p: Point, q: Point) -> Box:
+ a, b = minmax(p[0], q[0])
+ c, d = minmax(p[1], q[1])
+ return a, c, b, d
+
+
+def area(b: Box) -> int:
+ return (b[2] - b[0] + 1) * (b[3] - b[1] + 1)
+
+
+def minmax(x: int, y: int) -> tuple[int, int]:
+ return (x, y) if x < y else (y, x)
+
+
+if __name__ == '__main__':
+ main()