Created
December 1, 2023 16:18
-
-
Save jssee/e2b70bdf4a1fe226e546c96f3f90f8ca to your computer and use it in GitHub Desktop.
AOC-2023-1
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
local input = os.getenv("PWD") .. "/2023/1/input.txt" | |
local sum = 0 | |
for num, i in io.lines(input) do | |
local r = {} | |
-- each line becomes a table of values | |
for c in num:gmatch(".") do | |
-- remove values that are not numbers | |
local bit = tonumber(c) | |
-- make a table out of those numbers | |
table.insert(r, bit) | |
end | |
-- we only want 2 values in the new table, first and last | |
local m = { r[1], r[#r] } | |
-- make those 2 vales a single digit | |
local n = tonumber(table.concat(m)) | |
-- add it to sum | |
sum = sum + n | |
end | |
print("SUM: ", sum) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment