48 lines
1.1 KiB
Lua
48 lines
1.1 KiB
Lua
-- 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)
|