feat: solve day 6 puzzle 1

This commit is contained in:
2025-12-06 11:36:03 +01:00
parent bd36baa1ec
commit d9ac0c7a9f
5 changed files with 53 additions and 3 deletions

39
src/day06/puzzle1.lua Normal file
View File

@@ -0,0 +1,39 @@
local strings = require "cc.strings"
local puzzle1 = {}
function puzzle1.solve(input)
local lines = strings.split(input, "\n")
local problems = {}
local n = #lines
local ops = strings.split(lines[n], "%s+")
for i, line in ipairs(lines) do
local j = 1
for num in line:gmatch("(%d+)") do
local op = ops[j]
if i == 1 then
if op == "+" then
table.insert(problems, 0)
else
table.insert(problems, 1)
end
end
local val = tonumber(num)
if op == "+" then
problems[j] = problems[j] + val
else
problems[j] = problems[j] * val
end
j = j + 1
end
end
local total = 0
for _, val in ipairs(problems) do
total = total + val
end
return total
end
return puzzle1

7
src/day06/puzzle2.lua Normal file
View File

@@ -0,0 +1,7 @@
local puzzle2 = {}
function puzzle2.solve(input)
return 0
end
return puzzle2