Forgot to commit the last few days

This commit is contained in:
2025-12-12 06:23:45 +01:00
parent 50ca045070
commit ff3a3309a2
14 changed files with 1850 additions and 2 deletions

24
2025/Day10/Day10.lua Normal file
View File

@@ -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)

0
2025/Day10/full Normal file
View File

3
2025/Day10/test Normal file
View File

@@ -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}

47
2025/Day12/Day12.lua Normal file
View File

@@ -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)

33
2025/Day12/test Normal file
View File

@@ -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

View File

@@ -33,3 +33,48 @@ for R = 2, rows do
end end
print("Total splits " .. splits) print("Total splits " .. splits)
print("Total quantumsplits " .. quantumsplits) 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)

121
2025/Day8/Day8.lua Normal file
View File

@@ -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)

1000
2025/Day8/full Normal file

File diff suppressed because it is too large Load Diff

20
2025/Day8/test Normal file
View File

@@ -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

38
2025/Day9/Day9.lua Normal file
View File

@@ -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)

496
2025/Day9/full Normal file
View File

@@ -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

8
2025/Day9/test Normal file
View File

@@ -0,0 +1,8 @@
7,1
11,1
11,7
9,7
9,5
2,5
2,3
7,3

View File

@@ -4,8 +4,9 @@ vim.api.nvim_create_autocmd("BufWritePost", {
group = vim.api.nvim_create_augroup("AutoRunCode", { clear = true }), group = vim.api.nvim_create_augroup("AutoRunCode", { clear = true }),
pattern = "*.lua", pattern = "*.lua",
callback = function() callback = function()
local bufnr = 21 local day = 12
vim.fn.jobstart({ "lua", "Day7/Day7.lua" }, { local bufnr = 43
vim.fn.jobstart({ "lua", "Day" .. day .. "/Day" .. day .. ".lua" }, {
stdout_buffered = true, stdout_buffered = true,
on_stdout = function(_, data) on_stdout = function(_, data)
if data then if data then

View File

@@ -26,3 +26,15 @@ function tablelength(T)
end end
return count return count
end 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