summaryrefslogtreecommitdiff
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
parent749a3aae2231aee5f30b8d0a1dd075b12a678593 (diff)
day09 part1
-rwxr-xr-x2025/day09.py84
-rw-r--r--2025/in/day09.pzl496
-rw-r--r--2025/in/day09.ref8
3 files changed, 588 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)
+
diff --git a/2025/in/day09.pzl b/2025/in/day09.pzl
new file mode 100644
index 0000000..209b3f5
--- /dev/null
+++ b/2025/in/day09.pzl
@@ -0,0 +1,496 @@
+98484,50296
+98484,51511
+98068,51511
+98068,52739
+98204,52739
+98204,53955
+98065,53955
+98065,55193
+98148,55193
+98148,56358
+97604,56358
+97604,57491
+96980,57491
+96980,58746
+97139,58746
+97139,59978
+97095,59978
+97095,61198
+96956,61198
+96956,62270
+96225,62270
+96225,63587
+96414,63587
+96414,64565
+95449,64565
+95449,65647
+94880,65647
+94880,67111
+95349,67111
+95349,68081
+94475,68081
+94475,69020
+93586,69020
+93586,70291
+93460,70291
+93460,71309
+92780,71309
+92780,72273
+92012,72273
+92012,73647
+91997,73647
+91997,74719
+91412,74719
+91412,75598
+90516,75598
+90516,76662
+89923,76662
+89923,77622
+89174,77622
+89174,78826
+88758,78826
+88758,79307
+87388,79307
+87388,80260
+86652,80260
+86652,81357
+86079,81357
+86079,82346
+85365,82346
+85365,83251
+84555,83251
+84555,83916
+83504,83916
+83504,85343
+83188,85343
+83188,85814
+81962,85814
+81962,86434
+80894,86434
+80894,87138
+79906,87138
+79906,88493
+79422,88493
+79422,88852
+78166,88852
+78166,89914
+77420,89914
+77420,90451
+76306,90451
+76306,91006
+75213,91006
+75213,91549
+74118,91549
+74118,91952
+72951,91952
+72951,92598
+71921,92598
+71921,93323
+70924,93323
+70924,93832
+69816,93832
+69816,94434
+68747,94434
+68747,94398
+67421,94398
+67421,95160
+66412,95160
+66412,95698
+65309,95698
+65309,96214
+64190,96214
+64190,96511
+63001,96511
+63001,96798
+61812,96798
+61812,96703
+60537,96703
+60537,96605
+59281,96605
+59281,97305
+58180,97305
+58180,97378
+56962,97378
+56962,97758
+55786,97758
+55786,97680
+54554,97680
+54554,97836
+53349,97836
+53349,98072
+52143,98072
+52143,98251
+50928,98251
+50928,97716
+49708,97716
+49708,97822
+48495,97822
+48495,97567
+47296,97567
+47296,98145
+46037,98145
+46037,98011
+44821,98011
+44821,97268
+43686,97268
+43686,97123
+42486,97123
+42486,96852
+41306,96852
+41306,97262
+39986,97262
+39986,96273
+38963,96273
+38963,96510
+37654,96510
+37654,95954
+36546,95954
+36546,95742
+35340,95742
+35340,95515
+34131,95515
+34131,95176
+32954,95176
+32954,94900
+31745,94900
+31745,93885
+30849,93885
+30849,93352
+29759,93352
+29759,92762
+28699,92762
+28699,92848
+27283,92848
+27283,91912
+26400,91912
+26400,90934
+25565,90934
+25565,90815
+24211,90815
+24211,89807
+23414,89807
+23414,89156
+22389,89156
+22389,88767
+21166,88767
+21166,87987
+20222,87987
+20222,86811
+19607,86811
+19607,86261
+18483,86261
+18483,85509
+17522,85509
+17522,84593
+16712,84593
+16712,83928
+15654,83928
+15654,82618
+15263,82618
+15263,81870
+14288,81870
+14288,81261
+13132,81261
+13132,79842
+12941,79842
+12941,79331
+11624,79331
+11624,78395
+10831,78395
+10831,77227
+10367,77227
+10367,76352
+9478,76352
+9478,75310
+8835,75310
+8835,74112
+8460,74112
+8460,72803
+8318,72803
+8318,72056
+7139,72056
+7139,70898
+6729,70898
+6729,69611
+6620,69611
+6620,68541
+6054,68541
+6054,67501
+5398,67501
+5398,66555
+4447,66555
+4447,65113
+4885,65113
+4885,64035
+4290,64035
+4290,62971
+3598,62971
+3598,61657
+3814,61657
+3814,60628
+2893,60628
+2893,59454
+2524,59454
+2524,58148
+2878,58148
+2878,56977
+2517,56977
+2517,55774
+2338,55774
+2338,54550
+2363,54550
+2363,53325
+2503,53325
+2503,52132
+2179,52132
+2179,50928
+1712,50928
+1712,50273
+94737,50273
+94737,48494
+2140,48494
+2140,47295
+2419,47295
+2419,46101
+2629,46101
+2629,44890
+2626,44890
+2626,43634
+2344,43634
+2344,42420
+2463,42420
+2463,41172
+2423,41172
+2423,40023
+2913,40023
+2913,38839
+3204,38839
+3204,37586
+3236,37586
+3236,36431
+3650,36431
+3650,35238
+3937,35238
+3937,34268
+4876,34268
+4876,33112
+5244,33112
+5244,31915
+5516,31915
+5516,30719
+5816,30719
+5816,29532
+6162,29532
+6162,28424
+6685,28424
+6685,27558
+7670,27558
+7670,26425
+8131,26425
+8131,25278
+8584,25278
+8584,24437
+9541,24437
+9541,23196
+9866,23196
+9866,22350
+10787,22350
+10787,21391
+11535,21391
+11535,20079
+11829,20079
+11829,19604
+13184,19604
+13184,18312
+13541,18312
+13541,17619
+14596,17619
+14596,16427
+15111,16427
+15111,15976
+16389,15976
+16389,15117
+17244,15117
+17244,13924
+17804,13924
+17804,13122
+18730,13122
+18730,12633
+19909,12633
+19909,12013
+20965,12013
+20965,11322
+21960,11322
+21960,10342
+22755,10342
+22755,10089
+24044,10089
+24044,8922
+24743,8922
+24743,8707
+26030,8707
+26030,7538
+26769,7538
+26769,6928
+27834,6928
+27834,6945
+29205,6945
+29205,6471
+30320,6471
+30320,5586
+31261,5586
+31261,4936
+32317,4936
+32317,4889
+33605,4889
+33605,4087
+34619,4087
+34619,3893
+35842,3893
+35842,4247
+37210,4247
+37210,3617
+38292,3617
+38292,3196
+39439,3196
+39439,2839
+40607,2839
+40607,2280
+41747,2280
+41747,2146
+42967,2146
+42967,2240
+44213,2240
+44213,2566
+45468,2566
+45468,2073
+46644,2073
+46644,2340
+47874,2340
+47874,1528
+49067,1528
+49067,1546
+50295,1546
+50295,1733
+51518,1733
+51518,2575
+52695,2575
+52695,1853
+53962,1853
+53962,2689
+55103,2689
+55103,2284
+56373,2284
+56373,3001
+57493,3001
+57493,2315
+58847,2315
+58847,3038
+59950,3038
+59950,3789
+61021,3789
+61021,3930
+62228,3930
+62228,3864
+63506,3864
+63506,4645
+64534,4645
+64534,4701
+65792,4701
+65792,5423
+66819,5423
+66819,5916
+67921,5916
+67921,5819
+69279,5819
+69279,6316
+70395,6316
+70395,6753
+71542,6753
+71542,7453
+72556,7453
+72556,7749
+73789,7749
+73789,8496
+74774,8496
+74774,9054
+75870,9054
+75870,9982
+76725,9982
+76725,10874
+77588,10874
+77588,11485
+78645,11485
+78645,12536
+79366,12536
+79366,12849
+80671,12849
+80671,13582
+81652,13582
+81652,14665
+82317,14665
+82317,15593
+83107,15593
+83107,16156
+84258,16156
+84258,17091
+85045,17091
+85045,17953
+85909,17953
+85909,18795
+86801,18795
+86801,20187
+87021,20187
+87021,20781
+88227,20781
+88227,22089
+88500,22089
+88500,23050
+89227,23050
+89227,23711
+90422,23711
+90422,24651
+91226,24651
+91226,26115
+91146,26115
+91146,26749
+92498,26749
+92498,27897
+92949,27897
+92949,29175
+93118,29175
+93118,30161
+93880,30161
+93880,31401
+94080,31401
+94080,32489
+94625,32489
+94625,33478
+95459,33478
+95459,34772
+95455,34772
+95455,35979
+95659,35979
+95659,37181
+95855,37181
+95855,38145
+96965,38145
+96965,39531
+96394,39531
+96394,40600
+97200,40600
+97200,41880
+96950,41880
+96950,43064
+97193,43064
+97193,44258
+97385,44258
+97385,45442
+97706,45442
+97706,46662
+97667,46662
+97667,47871
+97737,47871
+97737,49075
+98068,49075
+98068,50296
diff --git a/2025/in/day09.ref b/2025/in/day09.ref
new file mode 100644
index 0000000..c8563ea
--- /dev/null
+++ b/2025/in/day09.ref
@@ -0,0 +1,8 @@
+7,1
+11,1
+11,7
+9,7
+9,5
+2,5
+2,3
+7,3