adventofcode-2021/day10/part1.lua

36 lines
427 B
Lua
Raw Normal View History

2021-12-10 08:54:13 +01:00
#!/usr/bin/env luajit
require("deque")
require("utils")
opening = {
["["] = "]",
["{"] = "}",
["<"] = ">",
["("] = ")",
}
score = {
["]"] = 57,
["}"] = 1197,
[">"] = 25137,
[")"] = 3,
}
local sum = 0
for line in io.lines(arg[3]) do
d = deque()
for c in chars(line) do
if opening[c] then
d:append(opening[c])
else
if c ~= d:pop() then
sum = sum + score[c]
break
end
end
end
end
print(sum)