From: Yong Li Date: 2011-11-25T23:42:05+09:00 Subject: Re: Is high-speed sorting impossible with Ruby? Had a quick look at the problem and its comments. It seems that most time-exceeded solutions are caused by slow i/o instead of sorting. On Fri, Nov 25, 2011 at 8:06 PM, Gaurav C. wrote: > Well, first of all, I'm new to Ruby, and to this forum. So, hello. :) > > I've studied the poignant guide and it really has helped me pick up the > language pretty fast. After that, I started solving some coding puzzles > using Ruby. It just helps a lot to get used to the language I feel. > > I'm stuck with one such puzzle. I have solved it very easily since it is > pretty straight-forward, but the solution is being rejected (by the host > website) with the error 'Time Exceded'! I know that Ruby cannot compete > with the speed of C/C++ but it > has got to be able to answer a tiny puzzle on a website which accepts > solutions in Ruby? > > Here's the link to the puzzle. It's just a normal sorting. > http://www.codechef.com/problems/TSORT/ > > And this is my solution > array ||= [] > gets.to_i.times do >  array << gets > end > puts array.sort > > My question is, is there any other way I can achieve high-speed sorting > with Ruby? I'm using the basic Array#sort here, but is there a way to do > it faster (even though it means lot more lines of code)? > > Cheers, > Gaurav > > -- > Posted via http://www.ruby-forum.com/. > > -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Li, Yong Fushan Road 450, Room 9A Pudong New Area, Shanghai, 200122 P.R.China phone: +86-15021003368 email: gilbertly@gmail.com =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=