Forgot to commit the last few days
This commit is contained in:
47
2025/Day12/Day12.lua
Normal file
47
2025/Day12/Day12.lua
Normal 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
33
2025/Day12/test
Normal 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
|
||||
Reference in New Issue
Block a user