Files
adventofcode/2025/Day1b.lua
2025-12-01 13:38:17 +01:00

34 lines
784 B
Lua
Executable File

#!/bin/lua
local Dial = 50
local CountZero = 0
local CountClick = 0
for line in io.lines() do
local Direction, Count = line:match("^(%w)(%d+)$")
CountClick = CountClick + math.floor(Count / 100)
Count = Count - (math.floor(Count / 100) * 100)
if Direction == "L" then
Count = 0 - Count
end
if Dial == 0 then
Dial = Dial + Count
else
Dial = Dial + Count
if Dial < 0 or Dial > 100 then
CountClick = CountClick + 1
end
end
Dial = Dial % 100
if Dial == 0 then
CountZero = CountZero + 1
end
print("Direction=" .. Direction .. " Count=" .. Count .. " Dial=" .. Dial .. " CountClick=" .. CountClick)
end
local Total = CountZero + CountClick
print("Dial " .. Dial)
print("Zero " .. CountZero)
print("Clicks " .. CountClick)
print("Total " .. Total)
print("Done")