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

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)