15 lines
288 B
Lua
Executable File
15 lines
288 B
Lua
Executable File
#!/usr/bin/env luajit
|
|
require("utils")
|
|
|
|
local positions = split(io.open(arg[3]):read("*a"), ",")
|
|
foreach(positions, tonumber)
|
|
table.sort(positions)
|
|
|
|
local median = positions[#positions/2]
|
|
local cost = 0
|
|
for k, v in pairs(positions) do
|
|
cost = cost + math.abs(median - v)
|
|
end
|
|
|
|
print(cost)
|