36 lines
427 B
Lua
Executable File
36 lines
427 B
Lua
Executable File
#!/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)
|