First star done
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/lua
|
#!/usr/bin/lua
|
||||||
-- See https://adventofcode.com/2025/day/3
|
-- See https://adventofcode.com/2025/day/3
|
||||||
|
|
||||||
local DEBUG = true
|
local DEBUG = false
|
||||||
|
|
||||||
function debug(msg)
|
function debug(msg)
|
||||||
if DEBUG then
|
if DEBUG then
|
||||||
@@ -28,13 +28,24 @@ function MaxJolt(Battery)
|
|||||||
checkdigit = tonumber(value)
|
checkdigit = tonumber(value)
|
||||||
if firstdigit < checkdigit then
|
if firstdigit < checkdigit then
|
||||||
firstdigit = checkdigit
|
firstdigit = checkdigit
|
||||||
elseif seconddigit < checkdigit then
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local passedfirst = false
|
||||||
|
for key, value in pairs(b) do
|
||||||
|
checkdigit = tonumber(value)
|
||||||
|
if passedfirst and seconddigit < checkdigit then
|
||||||
seconddigit = checkdigit
|
seconddigit = checkdigit
|
||||||
end
|
end
|
||||||
|
if checkdigit == firstdigit then
|
||||||
|
passedfirst = true
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if seconddigit < lastdigit then
|
if seconddigit < lastdigit then
|
||||||
seconddigit = lastdigit
|
seconddigit = lastdigit
|
||||||
end
|
end
|
||||||
|
|
||||||
debug("First " .. firstdigit)
|
debug("First " .. firstdigit)
|
||||||
debug("Second " .. seconddigit)
|
debug("Second " .. seconddigit)
|
||||||
return tostring(firstdigit) .. tostring(seconddigit)
|
return tostring(firstdigit) .. tostring(seconddigit)
|
||||||
@@ -53,4 +64,12 @@ print("# Self Test")
|
|||||||
TestMaxJolt("987654321111111", "98")
|
TestMaxJolt("987654321111111", "98")
|
||||||
TestMaxJolt("811111111111119", "89")
|
TestMaxJolt("811111111111119", "89")
|
||||||
TestMaxJolt("234234234234278", "78")
|
TestMaxJolt("234234234234278", "78")
|
||||||
TestMaxJolt("818181911112111", "89")
|
TestMaxJolt("818181911112111", "92")
|
||||||
|
|
||||||
|
print("# Calculate MaxJolt")
|
||||||
|
local TotalJolt = 0
|
||||||
|
|
||||||
|
for battery_line in io.lines("full_input") do
|
||||||
|
TotalJolt = TotalJolt + MaxJolt(battery_line)
|
||||||
|
end
|
||||||
|
print("Total " .. TotalJolt)
|
||||||
|
|||||||
Reference in New Issue
Block a user