Files
adventofcode/2025/Day9/Day9.lua

39 lines
804 B
Lua

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