feat: solve day 6 puzzle 1
This commit is contained in:
39
src/day06/puzzle1.lua
Normal file
39
src/day06/puzzle1.lua
Normal 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
7
src/day06/puzzle2.lua
Normal file
@@ -0,0 +1,7 @@
|
||||
local puzzle2 = {}
|
||||
|
||||
function puzzle2.solve(input)
|
||||
return 0
|
||||
end
|
||||
|
||||
return puzzle2
|
||||
Reference in New Issue
Block a user