27 lines
495 B
Lua
Executable File
27 lines
495 B
Lua
Executable File
#!/usr/bin/env luajit
|
|
require("utils")
|
|
|
|
local hm = {}
|
|
for line in io.lines(arg[3]) do
|
|
local row = {}
|
|
for c in chars(line) do
|
|
table.insert(row, tonumber(c))
|
|
end
|
|
table.insert(hm, row)
|
|
end
|
|
|
|
local function get(r, c)
|
|
return (hm[r] or {})[c] or math.huge
|
|
end
|
|
|
|
local lowsum = 0
|
|
for r, row in pairs(hm) do
|
|
for c, col in pairs(row) do
|
|
if col < get(r - 1, c) and col < get(r, c - 1) and col < get(r + 1, c) and col < get(r, c + 1) then
|
|
lowsum = lowsum + col + 1
|
|
end
|
|
end
|
|
end
|
|
|
|
print(lowsum)
|