2021-12-05 12:17:39 +01:00
|
|
|
#!/usr/bin/env luajit
|
2021-12-05 12:10:59 +01:00
|
|
|
require("utils")
|
|
|
|
|
2021-12-05 10:11:11 +01:00
|
|
|
function readline()
|
|
|
|
local x1 = io.read("*n")
|
|
|
|
io.read(1) -- ","
|
|
|
|
local y1 = io.read("*n")
|
|
|
|
io.read(4) -- " -> "
|
|
|
|
local x2 = io.read("*n")
|
|
|
|
io.read(1) -- ","
|
|
|
|
local y2 = io.read("*n")
|
|
|
|
io.read("*l") -- "...\n"
|
|
|
|
return x1, y1, x2, y2
|
|
|
|
end
|
|
|
|
|
2021-12-05 11:48:31 +01:00
|
|
|
function mark(field, x, y)
|
|
|
|
local row = field[x] or {}
|
|
|
|
row[y] = (row[y] or 0) + 1
|
|
|
|
field[x] = row
|
|
|
|
end
|
|
|
|
|
2021-12-05 12:10:59 +01:00
|
|
|
local input = io.open(arg[3]):read("*a")
|
|
|
|
local lines = split(input, "\n")
|
2021-12-05 10:11:11 +01:00
|
|
|
|
|
|
|
local field = {}
|
2021-12-05 12:10:59 +01:00
|
|
|
for _, line in pairs(lines) do
|
|
|
|
local x1, y1, x2, y2 = unpack(split(line, "[^0-9]+"))
|
|
|
|
x1, y1, x2, y2 = tonumber(x1), tonumber(y1), tonumber(x2), tonumber(y2)
|
2021-12-05 11:48:31 +01:00
|
|
|
local x, y, dx, dy = x1, y1, sign(x2 - x1), sign(y2 - y1)
|
|
|
|
mark(field, x, y)
|
|
|
|
while x ~= x2 or y ~= y2 do
|
|
|
|
x, y = x + dx, y + dy
|
|
|
|
mark(field, x, y)
|
2021-12-05 10:11:11 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local count = 0
|
|
|
|
for r, row in pairs(field) do
|
|
|
|
for c, col in pairs(row) do
|
|
|
|
if col >= 2 then
|
|
|
|
count = count + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
print(count)
|