Skip to content

Instantly share code, notes, and snippets.

@dkaraush
Last active December 4, 2025 16:27
Show Gist options
  • Select an option

  • Save dkaraush/2ea3e6e1a6ba4dabadc3c9e661a5c660 to your computer and use it in GitHub Desktop.

Select an option

Save dkaraush/2ea3e6e1a6ba4dabadc3c9e661a5c660 to your computer and use it in GitHub Desktop.
function joltage(line, n)
local index = 1
local result = 0
for a = 1, n do
local maxDigit = line:byte(index)
for i = index, #line - (n - a) do
if line:byte(i) > maxDigit then
maxDigit = line:byte(i)
index = i
end
end
result = result * 10 + (maxDigit - 48)
index = index + 1
end
return result
end
local result1 = 0
local result2 = 0
for line in io.lines("input.txt", "l") do
result1 = result1 + joltage(line, 2)
result2 = result2 + joltage(line, 12)
end
print(result1)
print(result2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment