From ff3a3309a2572829b2935439261bca4338d7f31e Mon Sep 17 00:00:00 2001 From: Bas Grolleman Date: Fri, 12 Dec 2025 06:23:45 +0100 Subject: [PATCH] Forgot to commit the last few days --- 2025/Day10/Day10.lua | 24 + 2025/Day10/full | 0 2025/Day10/test | 3 + 2025/Day12/Day12.lua | 47 ++ 2025/Day12/test | 33 ++ 2025/Day7/Day7.lua | 45 ++ 2025/Day8/Day8.lua | 121 +++++ 2025/Day8/full | 1000 ++++++++++++++++++++++++++++++++++++++++++ 2025/Day8/test | 20 + 2025/Day9/Day9.lua | 38 ++ 2025/Day9/full | 496 +++++++++++++++++++++ 2025/Day9/test | 8 + 2025/autorun.lua | 5 +- 2025/functions.lua | 12 + 14 files changed, 1850 insertions(+), 2 deletions(-) create mode 100644 2025/Day10/Day10.lua create mode 100644 2025/Day10/full create mode 100644 2025/Day10/test create mode 100644 2025/Day12/Day12.lua create mode 100644 2025/Day12/test create mode 100644 2025/Day8/Day8.lua create mode 100644 2025/Day8/full create mode 100644 2025/Day8/test create mode 100644 2025/Day9/Day9.lua create mode 100644 2025/Day9/full create mode 100644 2025/Day9/test diff --git a/2025/Day10/Day10.lua b/2025/Day10/Day10.lua new file mode 100644 index 0000000..3715205 --- /dev/null +++ b/2025/Day10/Day10.lua @@ -0,0 +1,24 @@ +-- Advent of Code 2025 - Day 10 - Bas Grolleman +require("functions") +local filename = "Day10/test" +print("Day 10") + +local input = {} +for line in io.lines(filename) do + local switches = string.match(line, "%[([#.]+)%]") + local buttons = {} + for b in string.gmatch(line, "%(([%d,]+)%)") do + local sw = {} + for j in string.gmatch(b, "%d+") do + table.insert(sw, tonumber(j)) + end + table.insert(buttons, sw) + end + + table.insert(input, { + switches = switches, + buttons = buttons, + }) +end + +print_table(input) diff --git a/2025/Day10/full b/2025/Day10/full new file mode 100644 index 0000000..e69de29 diff --git a/2025/Day10/test b/2025/Day10/test new file mode 100644 index 0000000..dd91d7b --- /dev/null +++ b/2025/Day10/test @@ -0,0 +1,3 @@ +[.##.] (3) (1,3) (2) (2,3) (0,2) (0,1) {3,5,4,7} +[...#.] (0,2,3,4) (2,3) (0,4) (0,1,2) (1,2,3,4) {7,5,12,7,2} +[.###.#] (0,1,2,3,4) (0,3,4) (0,1,2,4,5) (1,2) {10,11,11,5,10,5} diff --git a/2025/Day12/Day12.lua b/2025/Day12/Day12.lua new file mode 100644 index 0000000..c7ee1bc --- /dev/null +++ b/2025/Day12/Day12.lua @@ -0,0 +1,47 @@ +-- Advent of Code 2025 - Day 12 - Bas Grolleman +require("functions") +print("Day 12") +local filename = "Day12/test" +local input = file_lines_to_table(filename) + +function parseInput(lines) + local packages = {} + local locations = {} + + -- Parse first dataset (patterns 0-5) + local pattern = {} + local patternNum = -1 + + for i, line in ipairs(lines) do + if line:match("^%d:$") then + -- New pattern number + patternNum = tonumber(line:sub(1, 1)) + pattern = {} + elseif line:match("^[%.#]+$") and #line == 3 and patternNum ~= -1 then + -- Pattern row + table.insert(pattern, line) + if #pattern == 3 then + packages[patternNum] = pattern + end + end + end + + -- Parse second dataset (dimension and coordinate data) + for i, line in ipairs(lines) do + local x, y, coords = line:match("^(%d+)x(%d+):%s+(.+)$") + if x and y then + local data = { x = tonumber(x), y = tonumber(y), coords = {} } + for num in coords:gmatch("%d+") do + table.insert(data.coords, tonumber(num)) + end + table.insert(locations, data) + end + end + + return packages, locations +end + +local shapes, locations = parseInput(input) + +print_table(shapes) +print_table(locations) diff --git a/2025/Day12/test b/2025/Day12/test new file mode 100644 index 0000000..e5e1b3d --- /dev/null +++ b/2025/Day12/test @@ -0,0 +1,33 @@ +0: +### +##. +##. + +1: +### +##. +.## + +2: +.## +### +##. + +3: +##. +### +##. + +4: +### +#.. +### + +5: +### +.#. +### + +4x4: 0 0 0 0 2 0 +12x5: 1 0 1 0 2 2 +12x5: 1 0 1 0 3 2 diff --git a/2025/Day7/Day7.lua b/2025/Day7/Day7.lua index 58f4f90..a5336c2 100644 --- a/2025/Day7/Day7.lua +++ b/2025/Day7/Day7.lua @@ -33,3 +33,48 @@ for R = 2, rows do end print("Total splits " .. splits) print("Total quantumsplits " .. quantumsplits) + +-- Okay, time to learn how to make a tree node +-- Great, I learned how to try a brute force (that will obviously never work) + +function createNode(col) + local node = { + col = col, + childeren = {}, + } + return node +end + +local root = createNode(math.ceil(cols / 2)) + +local active_nodes = { root } + +for row = 2, rows do + for k, n in ipairs(active_nodes) do + if next(n.childeren) == nil then + if input[row][n.col] == "^" then + local a = createNode(n.col - 1) + local b = createNode(n.col + 1) + table.insert(active_nodes, a) + table.insert(active_nodes, b) + n.childeren = { a, b } + end + end + end +end + +local gt = 0 +function count_table(t, indent) + indent = indent or "" + print(indent .. "c" .. t.col) + if next(t.childeren) ~= nil then + for k, v in pairs(t.childeren) do + count_table(v, indent .. " ") + end + else + gt = gt + 1 + end +end + +count_table(root) +print("Grand Total " .. gt) diff --git a/2025/Day8/Day8.lua b/2025/Day8/Day8.lua new file mode 100644 index 0000000..90db6f1 --- /dev/null +++ b/2025/Day8/Day8.lua @@ -0,0 +1,121 @@ +-- Advent of Code 2025 - Day 8 - Bas Grolleman +require("functions") + +-- Variables +local boxes = {} +local inputfile = "Day8/test" +local limit = 11 + +function distance(p1, p2) + return math.sqrt((p2.x - p1.x) ^ 2 + (p2.y - p1.y) ^ 2 + (p2.z - p1.z) ^ 2) +end +function boxes.find(id) + for i, box in ipairs(boxes) do + if box.id == id then + return box + end + end +end + +local id_counter = 0 +for line in io.lines(inputfile) do + local x, y, z = line:match("(%d+)%,(%d+)%,(%d+)") + id_counter = id_counter + 1 + local box = { + id = id_counter, + x = tonumber(x), + y = tonumber(y), + z = tonumber(z), + xyz = x .. "," .. y .. "," .. z, + } + table.insert(boxes, box) +end + +local distance_table = {} +for i, box1 in ipairs(boxes) do + for j, box2 in ipairs(boxes) do + if box1.id ~= box2.id then + table.insert(distance_table, { + id1 = box1.id, + id2 = box2.id, + d = distance(box1, box2), + }) + end + end +end +table.sort(distance_table, function(a, b) + return a.d < b.d +end) + +local circuit = 0 +for i, dt in ipairs(distance_table) do + box1 = boxes.find(dt.id1) + box2 = boxes.find(dt.id2) + if limit > 0 then + io.write(string.format("%2d Linking %2d <-> %2d %.0f", limit, box1.id, box2.id, dt.d)) + if box1.c == nil and box2.c == nil then + circuit = circuit + 1 + box1.c = circuit + box2.c = circuit + limit = limit - 1 + print(" C=" .. circuit .. " BOTH") + elseif box1.c ~= nil and box2.c ~= nil then + if box1.c == box2.c then + print(" C=" .. box1.c .. " ALREADY") + else + -- Oh look, we merge 2 circuits! + print(" Merging " .. box1.c .. " and " .. box2.c) + local remove = box2.c + for k, uc in ipairs(boxes) do + if uc.c == remove then + uc.c = box1.c + end + end + limit = limit - 1 + end + elseif box1.c == nil then + box1.c = box2.c + limit = limit - 1 + print(" C=" .. box1.c .. " HOOK BOX1") + elseif box2.c == nil then + box2.c = box1.c + limit = limit - 1 + print(" C=" .. box1.c .. " HOOK BOX2") + end + end +end +for k, box in ipairs(boxes) do + if box.c == nil then + circuit = circuit + 1 + box.c = circuit + end +end +table.sort(boxes, function(a, b) + return a.c < b.c +end) + +local lc = 0 +local circuit_size = {} + +for k, box in ipairs(boxes) do + if lc ~= box.c then + circuit_size[box.c] = 1 + print() + else + circuit_size[box.c] = circuit_size[box.c] + 1 + end + print(string.format("Box %2d Circuit %2d", box.id, box.c)) + lc = box.c +end + +print() +local circuit_size2 = {} +for k, v in pairs(circuit_size) do + circuit_size2[#circuit_size2 + 1] = v +end +table.sort(circuit_size2, function(a, b) + return b < a +end) +print_table(circuit_size2) +local total = circuit_size2[1] * circuit_size2[2] * circuit_size2[3] +print("Total size " .. total) diff --git a/2025/Day8/full b/2025/Day8/full new file mode 100644 index 0000000..40f0262 --- /dev/null +++ b/2025/Day8/full @@ -0,0 +1,1000 @@ +75262,24842,97390 +5850,23406,34462 +26020,4432,80875 +57825,52185,42207 +61244,41825,99111 +41106,37991,96738 +18548,46804,50777 +82345,90100,44635 +52588,93061,39246 +16907,17561,8557 +92859,22926,42537 +56374,41906,10940 +2000,60958,7605 +39763,11100,93449 +53412,83932,28008 +54240,64204,70671 +80662,7998,35309 +89694,37693,92407 +6882,81993,95279 +57743,18143,44156 +15357,86472,86437 +37821,2676,39005 +78028,15498,33943 +73455,91817,24669 +69014,70653,29680 +31018,57570,38701 +54084,72177,63033 +79073,6701,68127 +24909,24807,72769 +39610,70105,43679 +62176,27410,19864 +70000,47082,32572 +61292,48573,50417 +69409,8440,56324 +42608,12081,47670 +87,44167,33594 +83589,63789,87909 +59063,95984,12239 +658,47892,13542 +20431,74799,61297 +68129,32547,14635 +80290,33244,10238 +31125,96983,73988 +79158,86765,80128 +53520,50969,45504 +99372,94859,86959 +91833,6081,87947 +82142,49754,248 +42977,15055,52682 +40236,13624,9783 +6626,66584,71581 +50964,13098,43262 +88712,39030,7992 +64306,39521,57902 +55630,14333,47019 +88278,61775,5857 +64572,50658,28832 +81296,77836,19250 +34668,64128,70429 +52888,32457,61533 +77929,36250,22101 +64349,43779,84049 +58881,1994,31735 +4836,36925,97617 +69898,47721,4336 +28107,35754,15211 +43930,35043,7900 +44737,44493,5572 +33560,68887,18569 +59840,52,14324 +15539,46471,69008 +98516,75186,76208 +83522,14361,54066 +71732,96918,40240 +92537,98464,87448 +87908,26962,75634 +12909,65530,62533 +71661,53400,27310 +25895,24890,77023 +45200,1952,25791 +13136,39458,10136 +64752,9421,62112 +96186,19674,93928 +36231,56106,97701 +30611,11097,89190 +87778,98830,22631 +12401,46411,3622 +24677,94363,63454 +26915,31829,65002 +12036,10937,41421 +77442,15448,56797 +61092,88956,91312 +65174,90106,54312 +1075,15721,95492 +5,21511,9203 +97323,54205,9050 +96006,67311,22501 +80966,8774,38774 +21881,37731,60834 +88253,58395,84764 +78716,45227,71161 +30403,2163,8811 +76138,80056,12365 +42938,56573,68248 +74979,4593,38082 +63575,3132,55326 +99899,3772,34153 +62909,50284,15108 +56982,17787,94044 +2690,42818,44614 +49563,64985,95090 +60740,7931,50695 +4525,25954,39255 +91103,37024,97386 +33000,72993,95333 +83099,47314,71563 +36590,12074,44449 +9145,36544,68078 +8245,2679,14797 +82809,98437,83502 +53971,38961,63788 +28955,97410,87170 +50300,12403,15438 +49476,36404,21554 +18162,34692,58191 +93290,24616,73600 +54246,84846,92933 +40806,31587,28058 +76373,39231,96716 +66826,5098,7506 +94734,43171,46475 +71705,85599,98497 +67663,4097,61404 +82500,96773,2702 +68370,89771,44023 +47800,59189,65285 +25966,82983,27493 +64976,15801,68388 +99116,21319,85533 +48483,2338,29795 +83697,3677,59493 +38145,10661,28355 +28808,23232,75183 +13387,41652,80977 +86723,50964,85864 +23174,11535,17766 +59687,75042,83386 +99123,87809,42167 +55923,64301,46267 +72167,40352,89489 +76568,71227,24149 +979,92267,58701 +81547,2636,49121 +3816,90074,87760 +89230,232,67765 +70144,1848,99551 +58969,9283,10560 +60061,71754,32946 +85745,27804,13651 +61274,49870,73040 +74275,21179,44310 +64983,60749,70780 +33062,4100,34831 +70004,49330,6206 +17331,75995,34457 +71718,86569,78088 +58925,91889,81798 +35359,56724,70558 +41285,35883,96872 +42956,27172,57561 +79360,84610,67508 +99363,92588,44477 +39757,44157,41100 +42493,22319,61553 +27084,16939,1662 +14767,97940,29872 +75865,78925,1826 +66712,81761,41139 +90332,40513,66448 +42730,84596,12917 +56441,50851,60617 +17087,63607,46261 +89317,46528,28802 +74025,84931,5612 +96827,88307,15235 +89419,53018,97136 +22586,23288,28267 +70275,4956,85941 +99128,56853,40285 +18485,9337,89882 +80539,77748,12809 +53825,38619,83783 +63025,7883,82145 +83724,34506,91426 +93862,68208,76526 +65908,64759,31228 +42826,47675,29413 +23175,72036,63337 +5030,62272,78170 +69923,48075,8191 +47491,58965,32506 +68850,84352,41354 +88935,76952,43611 +49333,27375,95306 +78300,5938,20715 +62268,98740,89690 +20271,82447,20919 +54226,47217,79071 +98813,65884,88782 +18059,15832,66195 +79966,68849,16174 +95858,70026,1541 +6917,79328,28050 +15883,58059,37991 +98963,26566,80454 +237,65911,75990 +13198,10150,38092 +34998,3177,6318 +66046,71827,93294 +78134,85755,97725 +43606,90318,25493 +25295,15102,55105 +37479,33650,30845 +85140,72498,17264 +58319,64578,27600 +86755,2302,68798 +12897,87530,64740 +58797,96920,42995 +79865,90204,64512 +13847,14862,51523 +16168,83683,92615 +75271,32288,37848 +29624,19718,44783 +40139,33427,69800 +96847,37815,96947 +52122,19861,35523 +96665,50733,24876 +83504,15478,74412 +51064,74117,94678 +90558,60932,46608 +81170,60357,43859 +65767,91891,91013 +27242,81960,16359 +46369,85682,53722 +27045,11692,40498 +39184,55424,2817 +7447,47849,16498 +6771,52890,12270 +56404,79678,76258 +51994,44488,48796 +38292,85437,3684 +36367,84308,14192 +49858,62292,73987 +87623,3287,85978 +73597,21511,13016 +11974,13313,25105 +49412,32756,76490 +7515,31716,90380 +5215,21964,58462 +58211,58061,39607 +49790,28045,93038 +61551,25165,16143 +17744,6013,69024 +5583,16718,88539 +54283,29686,45057 +27678,31147,81616 +50076,826,60979 +44580,26949,79069 +4236,63031,28086 +33306,13057,81984 +72820,13703,45862 +34759,57709,11374 +9122,51469,57315 +55118,43874,35167 +60323,31058,48121 +30216,80714,32126 +54992,10085,63781 +4805,47767,87991 +12074,8329,71223 +3597,47761,97173 +12032,39133,11233 +80234,44615,46962 +47376,63102,31203 +32542,22354,95720 +91956,88363,36866 +92884,21915,48634 +93930,75183,82803 +65656,47744,62662 +79113,58176,7955 +1378,86533,61895 +23900,86937,17092 +12159,94462,80800 +17154,99143,79929 +70556,22549,74082 +66708,69377,68190 +19884,8376,61550 +29023,76495,36947 +98308,74199,77381 +76548,13409,49130 +82108,63144,32096 +70362,6378,64277 +75562,68681,56522 +32857,40115,47042 +73785,20182,44279 +15094,14339,12156 +65516,12356,15341 +55977,22643,61401 +83381,74630,30809 +82521,48688,55815 +57934,16733,42752 +78364,28191,17100 +15949,50826,47479 +84313,29625,77224 +4487,4263,49540 +97804,29912,38825 +76975,36898,65486 +79809,73889,5347 +7810,86410,39824 +75792,92582,32908 +52623,70799,79760 +22625,91139,66281 +85760,11385,65931 +27003,95214,96354 +20181,12703,21310 +89890,56037,49090 +83834,20989,45862 +69129,40114,5379 +10018,38490,52529 +48076,65630,72098 +62871,96056,58731 +83823,88063,33230 +96362,41370,62351 +2360,58174,96489 +50797,79261,27982 +45196,9580,1465 +85338,32546,96059 +37256,2744,35682 +50787,50484,24467 +41860,13636,82802 +53585,34541,65024 +7706,41586,30527 +32962,61588,83431 +89850,98554,86137 +45299,83209,1913 +16273,44053,30396 +71418,69058,10037 +68311,10414,64835 +77807,15757,4041 +83440,94301,40791 +96621,99539,18555 +17502,17287,83806 +20946,64955,43063 +15192,9040,69697 +18099,46464,99083 +2693,42845,55549 +81193,95378,94613 +12061,57980,51406 +91962,87545,63133 +49725,9671,42983 +32114,70266,42702 +74403,21979,20390 +99601,81399,83567 +3466,35286,20782 +25213,90741,56470 +3586,72992,94746 +10165,5772,4920 +2779,96181,66659 +93657,88805,91717 +2836,39048,53012 +92355,34981,64377 +32016,25640,9746 +21747,16851,86417 +55206,36642,17472 +46942,76101,80852 +24836,68044,21320 +8844,67471,53197 +21191,14782,7546 +56935,34019,56208 +10348,58596,80758 +63353,85054,6799 +12364,78925,87938 +8347,7685,97470 +1563,95528,59904 +42890,25011,40086 +78593,11163,96107 +61732,22330,37617 +2595,89245,26128 +26090,56273,97076 +99174,4082,3460 +48659,24903,73456 +23345,6379,88241 +91590,39851,9235 +8081,1151,4606 +2916,48124,87281 +31137,28125,81054 +64978,1285,15146 +61602,24406,72140 +93585,28933,2015 +79111,42802,70619 +16330,21724,81602 +85272,51390,92541 +15325,32239,81967 +45574,28352,40968 +83225,23414,73611 +14139,25405,67148 +74704,24247,19975 +10103,17272,8125 +7504,16417,74226 +75393,86090,24250 +33917,90595,550 +17262,94525,73120 +1717,98671,54405 +25,48326,21333 +83269,43443,44014 +22296,58576,33256 +63479,78639,14851 +96456,35770,95787 +89673,84774,81637 +33347,81432,91593 +85100,84990,22480 +66097,57459,46954 +42954,27739,92329 +18397,70122,46047 +31660,80497,4736 +91002,60552,49548 +7595,46921,19996 +12380,48385,70009 +94923,45618,36196 +16401,75336,29109 +2015,66230,52359 +69384,12447,70564 +52118,2481,99138 +85196,8142,93367 +17437,69472,58882 +58647,42107,93331 +38818,22131,48181 +43516,19014,52024 +55595,64736,81817 +1569,71192,36114 +72446,80121,88388 +22385,21380,62461 +90341,66290,41783 +14197,97612,99036 +67668,79651,45999 +43324,55153,74961 +28530,4554,41346 +27932,80508,84863 +65083,52647,85182 +88396,49433,81024 +76264,99781,27781 +56348,72389,28739 +39936,31025,96939 +97523,10413,78833 +78015,62922,52493 +2245,39898,76829 +75355,79937,55897 +97922,40231,95610 +38348,28436,49823 +24112,64468,4050 +24018,27579,35524 +58722,26914,55929 +13866,253,54514 +21032,89964,4281 +59805,61027,75188 +85233,99633,64652 +60926,60969,4708 +39443,9570,54979 +45527,82006,66021 +95265,40127,13259 +81870,74382,97641 +41907,99358,40606 +40114,1148,34030 +38291,95152,97552 +47800,6858,7381 +18673,6526,65627 +6793,63553,45361 +47220,78516,5094 +12858,19152,59037 +27145,61378,33557 +98015,34931,91636 +32989,58642,42724 +26727,88552,20421 +45718,83574,60204 +10679,77300,64225 +11043,40605,2114 +6602,23538,498 +58544,4260,9517 +71074,20952,31277 +63816,3486,26801 +34780,28009,82131 +1818,90854,32605 +9968,7806,55957 +8445,95854,43405 +95558,68362,4327 +3749,84154,84038 +78047,77153,59054 +28640,17140,46958 +77270,39407,3691 +16565,86561,24802 +77089,72661,34104 +4827,80869,3137 +18723,20289,25400 +45110,54068,74426 +5779,27972,73057 +8641,19755,14819 +30401,51083,87089 +21894,75742,83259 +46894,93761,89960 +24408,21871,36323 +30448,47359,83517 +10047,85762,82452 +27151,82140,28083 +89569,93676,43952 +94606,42622,31389 +27450,53153,71453 +62771,8267,47410 +73162,6742,90532 +66534,64660,59571 +91632,55151,28222 +97574,87242,63222 +1736,17989,44839 +62445,79224,59532 +504,56279,13993 +23050,70356,51760 +56224,63692,61521 +68958,80266,83087 +36251,92245,96131 +71766,79134,25518 +34820,42253,64962 +30523,2035,88243 +44274,78287,2625 +99327,76790,73194 +5953,30864,98449 +58008,96393,59736 +5601,36611,93681 +66475,56884,65432 +34070,48135,7479 +40737,38744,42624 +6678,18753,12885 +77,64413,40809 +83977,69185,58298 +33635,6712,32984 +44556,23051,3919 +68858,14742,40449 +37100,69040,18211 +38791,78887,20546 +36842,36768,5191 +45569,44414,15170 +12579,65439,25527 +32289,61682,2110 +36841,59949,28933 +32028,12195,67998 +35047,77630,89711 +73011,91221,63358 +46945,81804,34423 +86175,94501,87736 +96533,97476,1048 +48738,92892,64732 +6460,91759,12190 +60348,54811,45470 +19332,3238,26289 +18454,37178,79433 +24949,76068,82542 +73338,46837,58056 +91273,15670,96538 +48748,60112,69938 +77215,10457,57299 +41781,63863,11847 +46233,67503,97496 +90461,27845,65631 +51689,41306,27664 +71745,16001,732 +36766,8778,83954 +21694,5084,16519 +98134,7621,87922 +2415,90371,78079 +58280,15639,10860 +90773,28864,55577 +93108,97074,27928 +29830,80080,88610 +55545,83797,95511 +21914,14155,50095 +89587,28752,75666 +60291,2712,18661 +72660,30564,59684 +14900,2859,66341 +40023,88458,22851 +26232,31189,39892 +1683,72697,99200 +44194,69244,3984 +46260,8388,54300 +79623,34868,79042 +77380,98913,61322 +82029,73672,79643 +53903,29044,38509 +82203,49345,4975 +45267,84093,89046 +72217,3516,91658 +48826,28305,39522 +72252,24679,12661 +65895,51504,95055 +28110,672,80140 +47522,69674,25987 +74179,25586,3934 +84070,44985,27877 +29141,74269,93548 +86291,51777,83757 +60924,98097,17250 +90209,26377,77022 +29017,64770,81652 +84131,25087,64962 +96857,66562,67361 +90585,26582,63251 +46702,21168,87615 +75447,44338,15086 +8446,66506,92985 +21165,99848,72196 +93870,90559,2365 +17969,8983,26107 +15116,53565,22104 +28507,19074,4502 +53292,92824,51787 +82702,95935,38405 +28281,99559,94690 +72670,283,40387 +88584,61080,2076 +22448,43434,7187 +2952,4047,99068 +7974,12852,499 +62420,99122,16812 +6813,10595,15339 +25389,15790,96931 +74110,60375,44615 +16620,23273,68517 +60291,20708,38303 +99377,93159,22785 +93525,58254,93787 +20837,80308,70460 +68612,27879,87104 +71305,97383,34267 +61939,76762,15886 +97683,33004,35539 +42145,4704,91656 +14808,36689,71799 +32717,12323,47135 +50240,76974,8231 +75799,85448,61738 +94539,84078,19280 +7698,30600,68537 +45769,48843,33653 +96870,65134,30542 +96979,14987,75275 +36741,39369,43350 +88133,37494,91835 +87234,23897,53525 +66238,34015,78186 +5230,79513,94762 +55433,53379,12977 +37769,40412,90961 +12782,30093,34271 +17123,12319,48348 +1819,11274,14741 +91867,73849,38421 +81907,56692,77936 +4837,59942,35794 +59629,59877,40020 +54371,24925,7322 +21646,35216,26232 +64723,63855,1021 +14844,47397,83879 +42552,50906,74443 +82653,24824,49660 +6407,39351,30433 +23656,50447,53105 +89227,72959,71099 +7224,57097,68103 +48756,60308,51341 +47462,48779,8402 +44460,16581,30688 +23930,57915,41131 +7258,30193,79218 +87940,89653,66329 +73295,4984,48222 +97100,47489,77245 +14421,17028,10435 +31699,21917,39952 +91655,42735,72609 +86237,40816,55662 +43507,21725,34496 +67400,64636,39080 +92059,92330,77041 +35134,50087,79970 +68004,41682,3009 +17610,11618,34437 +73628,43319,64573 +30495,95261,56399 +66191,1864,32994 +56998,19291,77007 +37401,83544,24392 +77745,53733,75061 +57933,81433,23571 +40136,18788,2600 +36152,10333,73469 +31001,61608,33448 +55218,29322,28259 +81911,75959,1178 +67561,19729,92147 +64132,21530,63995 +89254,61407,93259 +65672,67425,86001 +77837,10982,89282 +70936,71460,46596 +95394,76056,55349 +66343,73321,14785 +49178,67174,41010 +60813,38771,10897 +47421,35149,93914 +84030,14409,36058 +95082,69866,20025 +59286,99849,68610 +19344,91853,69720 +77547,93817,11382 +91404,73403,31949 +3330,10144,93368 +54986,22936,20176 +54971,82490,86831 +53845,73830,69316 +23885,77851,63157 +62082,46454,46039 +31022,7928,4986 +2552,27465,78787 +52120,58664,50366 +41962,90889,38907 +58766,43075,97084 +66757,97718,65157 +52923,23254,37364 +71325,80139,904 +19111,26011,20724 +4457,76880,57867 +45735,35142,25197 +77086,22720,78185 +37500,80965,93898 +88596,56846,78055 +96834,7850,11857 +76293,41028,16035 +48372,21173,64884 +28969,22124,32536 +72524,37700,40478 +83137,56770,85366 +47875,38170,78712 +11933,46345,45684 +3910,25418,50831 +35849,6604,85496 +41107,68749,95235 +94441,74841,21404 +91794,65951,27529 +44663,3688,95393 +77249,58184,57177 +48047,28829,9619 +46259,54161,91290 +64249,78091,91827 +73352,39494,36471 +18066,28201,69867 +17196,93950,65208 +11156,24592,36547 +2481,35874,26552 +15762,79992,67460 +97951,21601,4033 +69591,99282,31693 +85375,84461,31372 +62140,46891,74355 +28667,39836,62584 +2674,36055,71277 +95827,21130,98623 +32838,96720,50781 +54176,78411,9317 +36254,86296,61790 +11374,59779,86003 +39057,40194,58058 +4809,38328,46114 +38308,16503,24496 +3780,26909,52235 +10922,14253,55820 +29243,70622,57336 +38158,61465,20167 +32618,59205,56780 +10782,34434,5595 +64863,84860,85134 +30653,18807,90894 +43109,54109,97496 +95740,67640,79760 +41981,66870,67698 +84674,63189,97003 +62625,51302,38692 +14056,10767,32137 +78769,17047,9491 +21543,45908,36405 +73794,66895,93628 +69363,68444,50649 +89832,49076,3097 +75245,54060,82106 +24276,56468,47245 +22311,20907,89965 +44836,30593,40045 +75846,20238,16781 +20656,32674,94106 +40802,50103,83657 +27434,10932,30162 +72554,71925,3970 +76881,46838,41886 +19453,36798,2224 +47581,92428,66536 +977,73472,28609 +24638,80854,96404 +95078,64795,50394 +97087,62817,97221 +96263,9152,15700 +9197,30594,59844 +93152,13984,67948 +10628,33838,49116 +49106,90919,11349 +55654,76035,14135 +98402,764,91644 +2781,77227,75113 +16571,18521,23196 +76467,81961,78032 +96113,64076,66902 +61513,22398,16596 +75334,33423,34297 +86604,35218,44306 +70230,37498,6650 +71025,16550,54137 +55458,36261,34909 +62839,12840,53040 +84351,87243,54511 +87932,15633,20502 +1075,69252,3641 +59974,47685,71366 +40536,28711,50337 +37734,44467,74701 +67345,542,99999 +76594,75604,56864 +79693,73166,68737 +72773,7092,17152 +86941,83451,6395 +55673,15109,60686 +79414,38113,34303 +85573,90847,70663 +87522,64310,71977 +1413,89558,92045 +18347,64054,45274 +90225,94315,67461 +33517,68256,47691 +66740,15565,43962 +32099,27313,70789 +78932,79958,24578 +89282,75813,31839 +49247,35393,52839 +20711,93047,69200 +89508,25473,17547 +77440,64312,46249 +8869,779,98007 +24953,23442,11262 +61964,50817,27869 +8999,82161,83617 +70330,30450,38083 +48322,78201,85911 +17362,3237,37153 +19126,85037,65869 +47722,79585,41736 +75266,61878,73726 +46520,31539,13415 +28264,85229,59271 +77989,56731,49339 +69765,7680,32312 +12002,52388,52501 +88607,13115,64021 +99371,61697,92937 +40635,64783,57191 +611,60837,78337 +44653,89599,8900 +93283,7378,43805 +26817,80327,80941 +36150,607,70734 +10849,43791,86016 +52933,24001,51542 +60326,27459,5481 +96193,58906,42590 +80272,737,63037 +67159,37151,38049 +96100,77713,81135 +50720,32253,9837 +33683,93117,34808 +75894,92517,83345 +48756,56970,91636 +45445,46984,23594 +39976,16007,6223 +4533,44967,70487 +36990,31998,4913 +94120,67774,51553 +64898,72288,66383 +35683,29820,87520 +52848,20708,9678 +61123,16018,60472 +1280,21345,38345 +32263,50713,17902 +6133,83203,51478 +24561,89272,62541 +93317,81250,1729 +17419,11448,68038 +45941,8715,89819 +82219,27901,27987 +35880,3088,39912 +16485,78376,86825 +12529,29327,300 +85726,61386,80453 +32142,45021,6977 +1672,17985,99384 +41861,58314,70313 +86173,9417,67747 +36214,69295,47584 +49486,65091,45782 +29917,8258,49261 +95540,1728,76396 +76773,55900,91635 +58731,9009,18518 +66176,72354,62922 +82620,58228,22569 +23138,70543,17444 +23778,36970,47975 +14040,55559,5569 +60372,45465,36550 +96640,30738,679 +25627,84121,83608 +88881,96345,3205 +871,31245,28276 +76386,51292,95923 +70999,68869,5732 +61813,42964,16301 +81393,66093,59343 +1466,92655,98648 +48535,51201,3507 +84623,25412,63168 +22184,59246,76896 +69492,23068,98918 +85393,73288,86934 +4588,4907,78250 +22234,22908,27316 +48748,5735,43565 +57398,64990,24277 +43435,79352,55819 +56151,24364,2633 +58076,94436,79244 +49671,92070,25875 +45586,35009,20658 +35881,54448,89218 +37643,9222,28337 +45327,88053,13160 +87802,88377,62857 +56860,45459,36554 +73766,99786,68397 +41728,45558,88367 +98380,14029,2115 +57768,35536,36023 +71539,84869,53667 +16431,53382,76965 +37017,33319,74871 +96323,94954,58006 +71043,56387,45593 +64266,63660,54757 +33413,64268,83913 +63177,32021,13207 +42858,70925,28527 +41384,91659,29622 +80039,40668,80502 +97950,62218,72997 +63623,34970,17480 +53205,51159,64066 +72590,16752,31495 +86222,84380,57074 +9030,43579,61644 +89647,51399,59748 +99669,76008,39545 +19881,59511,23797 +64382,25832,75722 +33691,5027,60125 +49765,57615,48705 +48315,41167,13774 +97557,2018,94856 +21240,78303,95541 +80115,91673,80307 +29419,26631,98245 +34849,82172,63116 +26079,26569,40406 +91752,44444,7935 +36759,35015,55368 +25026,64985,95779 +94312,84222,94586 +85238,41077,16199 +76631,12193,49306 diff --git a/2025/Day8/test b/2025/Day8/test new file mode 100644 index 0000000..e98a3b6 --- /dev/null +++ b/2025/Day8/test @@ -0,0 +1,20 @@ +162,817,812 +57,618,57 +906,360,560 +592,479,940 +352,342,300 +466,668,158 +542,29,236 +431,825,988 +739,650,466 +52,470,668 +216,146,977 +819,987,18 +117,168,530 +805,96,715 +346,949,466 +970,615,88 +941,993,340 +862,61,35 +984,92,344 +425,690,689 diff --git a/2025/Day9/Day9.lua b/2025/Day9/Day9.lua new file mode 100644 index 0000000..d78a26f --- /dev/null +++ b/2025/Day9/Day9.lua @@ -0,0 +1,38 @@ +-- Advent of Code 2025 - Day 9 - Bas Grolleman +require("functions") +local filename = "Day9/full" +local grid = {} +for line in io.lines(filename) do + local y, x = line:match("(%d+),(%d+)") + table.insert(grid, { + x = x, + y = y, + }) +end + +function size(p1, p2) + width = math.abs(p1.x - p2.x) + 1 + height = math.abs(p1.y - p2.y) + 1 + -- print(p1.x .. "," .. p1.y) + -- print(p2.x .. "," .. p2.y) + -- print(width .. " " .. height .. " " .. (width * height)) + return width * height +end + +testsize = size({ y = 2, x = 5 }, { y = 9, x = 7 }) +print("Testing size function 24=" .. testsize) + +local distance = {} +local biggest = 0 +for k1, p1 in ipairs(grid) do + for k2, p2 in ipairs(grid) do + if k1 ~= k2 then + local cs = size(p1, p2) + if biggest < cs then + biggest = cs + end + end + end +end + +print(biggest) diff --git a/2025/Day9/full b/2025/Day9/full new file mode 100644 index 0000000..a69d7f1 --- /dev/null +++ b/2025/Day9/full @@ -0,0 +1,496 @@ +97729,50076 +97729,51296 +98101,51296 +98101,52489 +97579,52489 +97579,53685 +97384,53685 +97384,54923 +97657,54923 +97657,56098 +97277,56098 +97277,57409 +97852,57409 +97852,58618 +97645,58618 +97645,59701 +96827,59701 +96827,60852 +96428,60852 +96428,62206 +96833,62206 +96833,63257 +96052,63257 +96052,64547 +96106,64547 +96106,65579 +95339,65579 +95339,66656 +94752,66656 +94752,67793 +94338,67793 +94338,68893 +93832,68893 +93832,70114 +93592,70114 +93592,71373 +93395,71373 +93395,72293 +92512,72293 +92512,73343 +91897,73343 +91897,74242 +91030,74242 +91030,75264 +90388,75264 +90388,76716 +90396,76716 +90396,77746 +89728,77746 +89728,78469 +88640,78469 +88640,79328 +87763,79328 +87763,80435 +87203,80435 +87203,81197 +86222,81197 +86222,82422 +85771,82422 +85771,83450 +85076,83450 +85076,83997 +83888,83997 +83888,84863 +83033,84863 +83033,85583 +82044,85583 +82044,86146 +80930,86146 +80930,87054 +80114,87054 +80114,88207 +79476,88207 +79476,88953 +78507,88953 +78507,89100 +77121,89100 +77121,89998 +76268,89998 +76268,90730 +75296,90730 +75296,91491 +74334,91491 +74334,91877 +73156,91877 +73156,92965 +72355,92965 +72355,93193 +71101,93193 +71101,93307 +69814,93307 +69814,94481 +69003,94481 +69003,94404 +67654,94404 +67654,94590 +66433,94590 +66433,94972 +65291,94972 +65291,95684 +64252,95684 +64252,95764 +63015,95764 +63015,96481 +61954,96481 +61954,97016 +60830,97016 +60830,96824 +59544,96824 +59544,96933 +58333,96933 +58333,97466 +57193,97466 +57193,97519 +55974,97519 +55974,98063 +54809,98063 +54809,98051 +53581,98051 +53581,97553 +52334,97553 +52334,97651 +51130,97651 +51130,98457 +49921,98457 +49921,98089 +48703,98089 +48703,98198 +47477,98198 +47477,98066 +46261,98066 +46261,98211 +45018,98211 +45018,97340 +43893,97340 +43893,96940 +42731,96940 +42731,97610 +41387,97610 +41387,97167 +40227,97167 +40227,96442 +39144,96442 +39144,96129 +37976,96129 +37976,96233 +36690,96233 +36690,95418 +35669,95418 +35669,95333 +34422,95333 +34422,94652 +33380,94652 +33380,94747 +32041,94747 +32041,93698 +31163,93698 +31163,93766 +29805,93766 +29805,93324 +28661,93324 +28661,92231 +27853,92231 +27853,91580 +26833,91580 +26833,90938 +25812,90938 +25812,90666 +24561,90666 +24561,90109 +23472,90109 +23472,89249 +22587,89249 +22587,88900 +21338,88900 +21338,87845 +20608,87845 +20608,86871 +19836,86871 +19836,86651 +18433,86651 +18433,85795 +17555,85795 +17555,85033 +16590,85033 +16590,83979 +15910,83979 +15910,82931 +15244,82931 +15244,82259 +14177,82259 +14177,81450 +13244,81450 +13244,79962 +13133,79962 +13133,79066 +12324,79066 +12324,78215 +11445,78215 +11445,77562 +10264,77562 +10264,76568 +9545,76568 +9545,75571 +8826,75571 +8826,74348 +8484,74348 +8484,73127 +8174,73127 +8174,71929 +7853,71929 +7853,71119 +6768,71119 +6768,70177 +5898,70177 +5898,69010 +5503,69010 +5503,67775 +5291,67775 +5291,66490 +5254,66490 +5254,65440 +4588,65440 +4588,64229 +4390,64229 +4390,63161 +3719,63161 +3719,61906 +3707,61906 +3707,60884 +2748,60884 +2748,59625 +2777,59625 +2777,58428 +2533,58428 +2533,57250 +2158,57250 +2158,56013 +2166,56013 +2166,54801 +2012,54801 +2012,53548 +2396,53548 +2396,52345 +2224,52345 +2224,51147 +1656,51147 +1656,50072 +94821,50072 +94821,48704 +1947,48704 +1947,47473 +1714,47473 +1714,46314 +2606,46314 +2606,45085 +2429,45085 +2429,43818 +2078,43818 +2078,42673 +2686,42673 +2686,41423 +2588,41423 +2588,40315 +3254,40315 +3254,39122 +3467,39122 +3467,37842 +3353,37842 +3353,36687 +3756,36687 +3756,35489 +4009,35489 +4009,34425 +4674,34425 +4674,33261 +5026,33261 +5026,32299 +5893,32299 +5893,30932 +5763,30932 +5763,29853 +6339,29853 +6339,28853 +7065,28853 +7065,27792 +7653,27792 +7653,26722 +8221,26722 +8221,25751 +8958,25751 +8958,24347 +8992,24347 +8992,23553 +10012,23553 +10012,22792 +11043,22792 +11043,21448 +11249,21448 +11249,20320 +11784,20320 +11784,19298 +12470,19298 +12470,18383 +13291,18383 +13291,17538 +14186,17538 +14186,16973 +15368,16973 +15368,16305 +16413,16305 +16413,15189 +17016,15189 +17016,14061 +17635,14061 +17635,13278 +18578,13278 +18578,12499 +19523,12499 +19523,11649 +20413,11649 +20413,11087 +21522,11087 +21522,10687 +22731,10687 +22731,9652 +23501,9652 +23501,8892 +24469,8892 +24469,8416 +25611,8416 +25611,7694 +26607,7694 +26607,7717 +27999,7717 +27999,7221 +29101,7221 +29101,5974 +29857,5974 +29857,6014 +31208,6014 +31208,5324 +32237,5324 +32237,4797 +33341,4797 +33341,4546 +34545,4546 +34545,4275 +35734,4275 +35734,3822 +36867,3822 +36867,3473 +38033,3473 +38033,3316 +39245,3316 +39245,3285 +40478,3285 +40478,2410 +41549,2410 +41549,2176 +42752,2176 +42752,2354 +44009,2354 +44009,2339 +45230,2339 +45230,1651 +46396,1651 +46396,2515 +47668,2515 +47668,2238 +48866,2238 +48866,1731 +50077,1731 +50077,1760 +51300,1760 +51300,2114 +52505,2114 +52505,1767 +53751,1767 +53751,2525 +54904,2525 +54904,2175 +56169,2175 +56169,2272 +57390,2272 +57390,2287 +58630,2287 +58630,2843 +59770,2843 +59770,3189 +60941,3189 +60941,3339 +62161,3339 +62161,3636 +63346,3636 +63346,4379 +64394,4379 +64394,4452 +65650,4452 +65650,5365 +66612,5365 +66612,5912 +67693,5912 +67693,6101 +68922,6101 +68922,6848 +69911,6848 +69911,7300 +71030,7300 +71030,7134 +72478,7134 +72478,8240 +73266,8240 +73266,8910 +74277,8910 +74277,8894 +75713,8894 +75713,9778 +76601,9778 +76601,10262 +77753,10262 +77753,11519 +78351,11519 +78351,12051 +79472,12051 +79472,12886 +80361,12886 +80361,13859 +81126,13859 +81126,14157 +82487,14157 +82487,15284 +83106,15284 +83106,15908 +84201,15908 +84201,17230 +84585,17230 +84585,18173 +85341,18173 +85341,18808 +86452,18808 +86452,19633 +87364,19633 +87364,20943 +87663,20943 +87663,21458 +89000,21458 +89000,22587 +89520,22587 +89520,23435 +90448,23435 +90448,24516 +91031,24516 +91031,25468 +91826,25468 +91826,26924 +91732,26924 +91732,27979 +92322,27979 +92322,28858 +93275,28858 +93275,29960 +93800,29960 +93800,31074 +94298,31074 +94298,32188 +94798,32188 +94798,33493 +94789,33493 +94789,34651 +95141,34651 +95141,35573 +96241,35573 +96241,36887 +96106,36887 +96106,38070 +96380,38070 +96380,39184 +96949,39184 +96949,40315 +97514,40315 +97514,41545 +97610,41545 +97610,42787 +97591,42787 +97591,44060 +97244,44060 +97244,45256 +97407,45256 +97407,46404 +98233,46404 +98233,47631 +98240,47631 +98240,48860 +98007,48860 +98007,50076 diff --git a/2025/Day9/test b/2025/Day9/test new file mode 100644 index 0000000..c8563ea --- /dev/null +++ b/2025/Day9/test @@ -0,0 +1,8 @@ +7,1 +11,1 +11,7 +9,7 +9,5 +2,5 +2,3 +7,3 diff --git a/2025/autorun.lua b/2025/autorun.lua index 1f2e7b2..17f1287 100644 --- a/2025/autorun.lua +++ b/2025/autorun.lua @@ -4,8 +4,9 @@ vim.api.nvim_create_autocmd("BufWritePost", { group = vim.api.nvim_create_augroup("AutoRunCode", { clear = true }), pattern = "*.lua", callback = function() - local bufnr = 21 - vim.fn.jobstart({ "lua", "Day7/Day7.lua" }, { + local day = 12 + local bufnr = 43 + vim.fn.jobstart({ "lua", "Day" .. day .. "/Day" .. day .. ".lua" }, { stdout_buffered = true, on_stdout = function(_, data) if data then diff --git a/2025/functions.lua b/2025/functions.lua index c3b62eb..47c74bf 100644 --- a/2025/functions.lua +++ b/2025/functions.lua @@ -26,3 +26,15 @@ function tablelength(T) end return count end + +function print_table(t, indent) + indent = indent or "" + for k, v in pairs(t) do + if type(v) == "table" then + print(indent .. k .. ":") + print_table(v, indent .. " ") + else + print(indent .. k .. ": " .. tostring(v)) + end + end +end