add utils, use luajit which seems faster
This commit is contained in:
parent
87637a4682
commit
fad5da2e27
5 changed files with 33 additions and 25 deletions
|
@ -1,3 +1,5 @@
|
|||
require("utils")
|
||||
|
||||
function readline()
|
||||
local x1 = io.read("*n")
|
||||
io.read(1) -- ","
|
||||
|
@ -16,24 +18,19 @@ function mark(field, x, y)
|
|||
field[x] = row
|
||||
end
|
||||
|
||||
function sign(n)
|
||||
if n == 0 then return 0
|
||||
elseif n < 0 then return -1
|
||||
else return 1
|
||||
end
|
||||
end
|
||||
local input = io.open(arg[3]):read("*a")
|
||||
local lines = split(input, "\n")
|
||||
|
||||
io.input(arg[3])
|
||||
local x1, y1, x2, y2 = readline()
|
||||
local field = {}
|
||||
while x1 ~= nil do
|
||||
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)
|
||||
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)
|
||||
end
|
||||
x1, y1, x2, y2 = readline()
|
||||
end
|
||||
|
||||
local count = 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue