データの整列
Posted feedbacks - Lua
昨日から使い始めたLuaで投稿
1 2 3 4 5 6 7 8 9 10 11 | printt = function(t)
for k, v in pairs(t) do print(string.format('{%d, %d}', v[1], v[2])) end
print()
end
a = {{1,2}, {3,4}, {1,3}, {2,4}, {1,8}}
printt(a)
table.sort(a, function(b, c) return b[1] < c[1] or (b[1] == c[1] and b[2] < c[2]) end)
printt(a)
table.sort(a, function(b, c) return b[1]^2 + b[2]^2 < c[1]^2 + c[2]^2 end)
printt(a)
|


odz #5839() Rating1/1=1.00
(x, y) の座標情報を以下の2種類の方法で整列する機能を実現してください。
データの表現方法はタプルなり構造体/オブジェクトなり各自で適当に選んで下さい。
[ reply ]