summaryrefslogtreecommitdiff
path: root/2025/day09.py
diff options
context:
space:
mode:
authornekineki <nekineki@nekineki.net>2025-12-10 10:39:20 +0100
committernekineki <nekineki@nekineki.net>2025-12-10 10:39:20 +0100
commit3bc75bd2c26b972f5f683fff7d2d8e4f282263ab (patch)
tree90f4e31e20af85fd85aa2f83f7a6c1339ecf0b36 /2025/day09.py
parent749a3aae2231aee5f30b8d0a1dd075b12a678593 (diff)
day09 part1
Diffstat (limited to '2025/day09.py')
-rwxr-xr-x2025/day09.py84
1 files changed, 84 insertions, 0 deletions
diff --git a/2025/day09.py b/2025/day09.py
new file mode 100755
index 0000000..3887c16
--- /dev/null
+++ b/2025/day09.py
@@ -0,0 +1,84 @@
+#!/usr/bin/env python3
+from functools import reduce
+from re import findall
+from copy import deepcopy
+import sys
+# import numpy as np
+import png
+from itertools import chain
+
+filename = sys.argv[1] if len(sys.argv) == 2 \
+ else "in/" + sys.argv[0].split('/')[-1].rstrip(".py") + ".pzl"
+data = open(filename).read()
+lines = data.rstrip('\n').split('\n')
+
+
+points = []
+for line in lines:
+ x, y = [int(i) for i in line.split(',')]
+ points.append((x, y))
+
+
+A = []
+for i, p0 in enumerate(points):
+ for p1 in points[i+1:]:
+ x0, y0 = p0
+ x1, y1 = p1
+ a = (abs(x1 - x0)+1) * (abs(y1 - y0)+1)
+ A.append((a, p0, p1))
+
+A.sort(reverse=True)
+res1 = A[0][0]
+
+
+res2 = 0
+
+counter = 0
+B = set()
+for p0, p1 in chain(zip(points, points[1:]), [(points[-1], points[0])]):
+ x0, y0 = p0
+ x1, y1 = p1
+ BB = set()
+ if x0 == x1:
+ if y0 < y1:
+ for y in range(y0, y1+1):
+ B.add((x0, y))
+ BB.add((x0, y))
+ else:
+ for y in range(y1, y0+1):
+ B.add((x0, y))
+ BB.add((x0, y))
+
+ elif y0 == y1:
+ if x0 < x1:
+ for x in range(x0, x1+1):
+ B.add((x, y0))
+ BB.add((x, y0))
+ else:
+ for x in range(x1, x0+1):
+ B.add((x, y0))
+ BB.add((x, y0))
+ else:
+ assert False
+
+ # n = 1000
+ # img = [[0 for _ in range(n)] for _ in range(n)]
+ # for x,y in BB:
+ # img[y//100][x//100] = 1
+ # writer = png.Writer(width=n, height=n, bitdepth=1, greyscale=True)
+ # with open(f'pic/{counter:04d}.png', 'wb') as f:
+ # writer.write(f, img)
+ # counter += 1
+
+# n = 1000
+# img = [[0 for _ in range(n)] for _ in range(n)]
+# for x,y in B:
+# img[y//100][x//100] = 1
+# writer = png.Writer(width=n, height=n, bitdepth=1, greyscale=True)
+# with open('out.png', 'wb') as f:
+# writer.write(f, img)
+
+
+print('res1:', res1)
+print('res2:', res2)
+