Comment detail

データの整列 (Nested Flatten)

2値の配列で座標を表現して、その配列をソートします。

1
2
3
4
5
6
coordinates = Array.new(10) { [rand(10), rand(10)]}

# by dictionary
p coordinates.sort
# by distance
p coordinates.sort {|(x1, y1), (x2, y2)| (x1**2 + y1**2) <=> (x2**2 + y2**2) }

すいません言語指定し忘れました。 Rubyです。

Index

Feed

Other

Link

Pathtraq

loading...