From: Douglas Seifert Date: 2011-11-27T00:25:36+09:00 Subject: Re: Is high-speed sorting impossible with Ruby? --e89a8f3ba2ad6d031404b2a4e1f5 Content-Type: text/plain; charset=ISO-8859-1 Here is a port of the fastest solution on that site in Ruby. It of course underperforms the C# version by a couple of orders of magnitude, but that is to be expected, no? Perhaps it could be tweaked to be faster? n = STDIN.gets.to_i a = Array.new(1e6+1, 0) while n > 0 i = STDIN.gets.to_i a[i] += 1 n -= 1 end n = 0 while n < 1_000_001 times = a[n] n_str = n.to_s while times > 0 STDOUT.puts n_str times -= 1 end n += 1 end -Doug Seifert On Sat, Nov 26, 2011 at 4:43 AM, Gaurav C. wrote: > Hi Matthias, > > Well I tried the tweaks mentioned by you. The sorting is still slow. > I'm thinking it's because of the way I'm taking the input? Is there a > way to tweak that? Anything faster or better alternative than 'gets'? > > -- > Posted via http://www.ruby-forum.com/. > > --e89a8f3ba2ad6d031404b2a4e1f5--