From: Sylvester Keil Date: 2011-11-28T23:49:48+09:00 Subject: Re: Is high-speed sorting impossible with Ruby? On Nov 28, 2011, at 3:33 PM, Gaurav C. wrote: > Ryan Davis wrote in post #1034037: >> On Nov 27, 2011, at 09:51 , Douglas Seifert wrote: >> >> $stdin.gets >> puts $stdin.readlines.map(&:to_i).sort >> >> Neither solution seems fast enough to reach their arbritrary deadline of >> 5 seconds (with their data)... but it is good enough for me. I love the >> fact that I can write a 1-2 liner and be done and onto the next problem >> while others are still bit-twiddling in their lower level languages... > > Hi Ryan, > > Totally makes sense to move on instead of trying to fit into constraints > which are actually not meant for your choice of language. Also, could > you explain your code a bit (have just started using Ruby since few > days)? > > $stdin.gets > puts $stdin.readlines.map(&:to_i).sort > > It's interesting to take all the input at once but I run the code above > and it seems like it never stops taking input? $stdin.readlines will return when it reads EOF; to my understanding, that's why Ryan said the input data needs to be 'honest' in his previous post. On a Unix system you can test this by pressing Ctrl-D (to send EOF to the input stream).