advent23/01/main.lua

30 lines
657 B
Lua
Raw Normal View History

2023-12-03 04:01:21 +00:00
input = {};
for line in io.lines("./input.txt") do
table.insert(input, line)
end
parsed = {};
for key, value in pairs(input) do
local alphastrip = string.gsub(value, "[%a]", "");
if string.len(alphastrip) == 1 then
local doubled = alphastrip .. alphastrip;
table.insert(parsed, doubled);
elseif string.len(alphastrip) == 2 then
table.insert(parsed, alphastrip);
else
local digitstrip = string.match(alphastrip, "%d", 1) .. string.match(alphastrip, "%d", -1);
table.insert(parsed, digitstrip);
--print(digitstrip);
end
end
result = 0;
for key, value in pairs(parsed) do
result = value + result;
end
print(result);