On 25.11.2011 13:06, Gaurav C. wrote:
> Here's the link to the puzzle. It's just a normal sorting.

You _can_ treat it as a normal sorting puzzle, but you will not be able 
to write a good implementation regarding the execution time if you did.

> And this is my solution
> array ||= []

array is still empty/unassigned, so a direct assignment array = [] would 
be sufficient.

> gets.to_i.times do
>    array<<  gets
> end

well, how about converting the strings returned by gets to integer 
first? sorting integers is way faster than sorting strings.

> 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)?

Yes, there is, and I don”Ēt think it requires a lot more code. Think 
about sorting the numbers while reading them in, as the quick solutions 
tend to approach the problem in this way.

 Matthias