feat: solve day 1 puzzle 1
This commit is contained in:
25
src/day01/puzzle1.lua
Normal file
25
src/day01/puzzle1.lua
Normal file
@@ -0,0 +1,25 @@
|
||||
local utils = require "utils"
|
||||
local puzzle1 = {}
|
||||
|
||||
function puzzle1.solve(input)
|
||||
local password = 0
|
||||
local cursor = 50
|
||||
|
||||
local lines = utils.splitLines(input)
|
||||
for _, line in ipairs(lines) do
|
||||
local dir = line:sub(1, 1)
|
||||
local dist = tonumber(line:sub(2))
|
||||
if dir == "R" then
|
||||
cursor = cursor + dist
|
||||
else
|
||||
cursor = cursor - dist
|
||||
end
|
||||
cursor = cursor % 100
|
||||
if cursor == 0 then
|
||||
password = password + 1
|
||||
end
|
||||
end
|
||||
return password
|
||||
end
|
||||
|
||||
return puzzle1
|
||||
7
src/day01/puzzle2.lua
Normal file
7
src/day01/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