Skip to content

Instantly share code, notes, and snippets.

@jssee
Created December 1, 2023 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jssee/e2b70bdf4a1fe226e546c96f3f90f8ca to your computer and use it in GitHub Desktop.
Save jssee/e2b70bdf4a1fe226e546c96f3f90f8ca to your computer and use it in GitHub Desktop.
AOC-2023-1
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