From 181a1bf4039b37777e890f7f649de28f39a00143 Mon Sep 17 00:00:00 2001 From: Thibaud Date: Wed, 27 May 2026 19:22:44 +0200 Subject: [PATCH] 2025 day 9 part 1 --- adventofcode/2025/day9/day9.py | 64 +++++++++++++++++++++++++++++++ adventofcode/2025/day9/input.png | Bin 0 -> 1356 bytes 2 files changed, 64 insertions(+) create mode 100644 adventofcode/2025/day9/day9.py create mode 100644 adventofcode/2025/day9/input.png diff --git a/adventofcode/2025/day9/day9.py b/adventofcode/2025/day9/day9.py new file mode 100644 index 0000000..fffed39 --- /dev/null +++ b/adventofcode/2025/day9/day9.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 +import fileinput +from sys import argv + + +def area(a, b): + height = abs(a[1] - b[1]) + 1 + width = abs(a[0] - b[0]) + 1 + return height * width + + +def test_area(): + assert area((2, 5), (9, 7)) == 24, "Area between (2,5) and (9,7) should be 24" + assert area((7, 1), (11, 7)) == 35, "Area between (7,1) and (11,7) should be 35" + assert area((2, 5), (11, 1)) == 50, "Area between (2,5) and (11,1) should be 50" + + +def generate_ppm(inp, scale=100): + """Generate a PPM file with scaled-down coordinates""" + coords = [(x // scale, y // scale) for x, y in inp] + + max_x = max(x[0] for x in coords) + min_x = min(x[0] for x in coords) + max_y = max(x[1] for x in coords) + min_y = min(x[1] for x in coords) + + height = max_y - min_y + 1 + width = max_x - min_x + 1 + + print(f"Scaled dimensions: {width}x{height} (scale factor: {scale})") + print(f"Original dimensions: {max(x[0] for x in inp)}x{max(x[1] for x in inp)}") + + arr = [[0] * (width) for _ in range(height)] + for x, y in coords: + if 0 <= y < height and 0 <= x < width: + arr[y][x] = 1 + + with open("test.ppm", "w") as f: + f.write(f"P3\n{width} {height}\n255\n") + for row in arr: + for cell in row: + f.write(f"{cell * 255} 0 0 ") + f.write("\n") + + print("PPM file written to test.ppm") + + +def main(inp): + coords = [tuple(map(int, x.split(","))) for x in inp] + max_area = 0 + for a in coords: + for b in coords: + if a == b: + continue + max_area = max(max_area, area(a, b)) + print("Part 1:", max_area) + + +if __name__ == "__main__": + lines = [x.rstrip() for x in fileinput.input()] + # test_area() + main(lines) + # for vizualization + # generate_ppm([tuple(map(int, x.split(","))) for x in lines]) diff --git a/adventofcode/2025/day9/input.png b/adventofcode/2025/day9/input.png new file mode 100644 index 0000000000000000000000000000000000000000..2e22f85050f586e66e8cde7b6a9242b4c6e314b2 GIT binary patch literal 1356 zcmZ`&3s93s5Z;i40LFj~V}cD75fynE0!By(DR092sVLeBCIk{6P0M2tsPikKRRjdY zf+7VC)k+Zs#R3)$s1a>Yv{eHUjiQK(nu?;Rke<_-&a^X~xw~)n+xc$ycK3F~Mu*O} zm}db1vjt&6@c{TfwAChf#00QY?jf)jg~dk!e+aUwDE+RC@L^7*Dj0{qiAS#&jggBRM?!|wte1WKiS;5I! z;?%4(j_B(&1i)gl*lx^aZY)-!2aCg8&S81EFqs@Cv+IY9kbem_ekqnpHvhliw{rs@ z^L6?sLY8!6T4q-2M)`j=KAdH&zk@urm~ICkFa$yViMd11hSx`rFs(qJ{1PYmkyqY{ zd&BR)E-TWK2H1j&yIxR@Nb*3oND~A^T`n=PIyy;c`t_8})b9FcUjL#hU zxi>R(#%|5jrmsE>Hi}AXPdAUw%t+5H-uJk@w*Ef-?B=^$S~IsVCGFjCYmx1shn)6H z$5IumXQ?BPyPiJ7>vijW*p(*D!sYMvn_D2D)=a0x*; z`$`x7lV#bpdZqK9{4!a;yXy9S8nL`bW9|AgJs)RqlpMl>6;js*D#gmQX7_Y6Iq-%% z2%$P_lbF4uYHez$}Ka&o61_CG1(Fi<&D}SSG~f;p#UEu(wyjfNpx&xFbW^&sV86*pExw)+Dqv~fWxvu z92x;-em@1l=zVVzfOpmPE&zFRnsZ(IIAXzcbYu>MCH|_!fj+jM{wWeaTF6C?8V$=O z8CRM0q%0VqzCR=xDKmlL3d_Q4+7BdV*R65DxYiNJ zaF|_@zXdrcoF+7-Sk(q3rK3!wmnYZm-9IW!0M2BkEf`8yqc+3yiEmDsg(dNnK#u7( z%Ns>?k;J;@imWa_fSnn&8>~Jr9x&cft?C9}|2RGoyX4f$EqCC}QYm^TL&v@ybfVvV z=utLqA0iSl03JElPSssmvW;Bd7Eg&!I{kF(+4C?RFzkxjCYydUsCvub;SBzspONHV zYh7+12rI)cZp+mRlj@^P3W=~n5^Qs#X>zr=Qf1l@7{#XLB