「常識を覆すソートアルゴリズム!その名も"sleep sort"! - Islands in the byte stream」があまりにも面白いので,Rubyで作ってみました。
sleepsort.rb
#!/usr/bin/env ruby def f(n) Thread.new(n) do |s| sleep (n.to_f / 10.0) puts n end end ARGV.each do |arg| f arg.to_i end Thread.list.each do |t| t.join if t != Thread.current end
実行結果
$ ./sleepsort.rb 5 3 6 3 6 3 1 4 7 1 3 3 3 4 5 6 6 7