Last active
December 4, 2025 16:27
-
-
Save dkaraush/2ea3e6e1a6ba4dabadc3c9e661a5c660 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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