SIMPLE SORTING(CodeEval)

20141118 追記

floatの結果を下3桁で表示するというを見落としていた。。。
ソートのアルゴリズムを問う問題じゃなかった。すごい勘違いしてた。
 


simple sortなので挿入ソートか選択ソートのことだと思うのですが、
codeevalで採点するとスコアが低いです。なんでだろう。
どちらも試しましたが両方ともスコアが低いです。

CHALLENGE DESCRIPTION:

Write a program which sorts numbers.

INPUT SAMPLE:

Your program should accept as its first argument a path to a filename. Input example is the following

70.920 -38.797 14.354 99.323 90.374 7.581
-37.507 -3.263 40.079 27.999 65.213 -55.552

OUTPUT SAMPLE:

Print sorted numbers in the following way.

-38.797 7.581 14.354 70.920 90.374 99.323
-55.552 -37.507 -3.263 27.999 40.079 65.213

My Code

修正後

#!/usr/bin/env ruby -w
ARGF.each_line do |line|
  numbers = line.chomp.split.map(&:to_f)
  puts numbers.sort.map { |n| sprintf('%.3f', n) }.join(' ')
end

修正前

#!/usr/bin/env ruby -w

def selection_sort(numbers)
  tmp = numbers.dup
  res = []
  until tmp.empty?
    min_index = tmp.find_index(tmp.min)
    res << tmp.delete_at(min_index)
  end
  res
end

ARGF.each_line do |line|
  numbers = line.chomp.split.map(&:to_f)
  puts selection_sort(numbers).join(' ')
end