From: Brian Mitchell Date: 2005-09-20T17:24:59+09:00 Subject: Re: ruby idiom for python's for/else while/else On 9/20/05, Pit Capitain wrote: > William James schrieb: > > ... > > (2...50).select{|n|(2..Math.sqrt(n).to_i).select{|x|n % x == 0}.empty?} > > --> > > [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47] > > Should be a little bit more efficient: > > (2...50).reject{|n|(2..Math.sqrt(n)).find{|x|n % x == 0}} > > It's not what the OP wanted, though. > > Regards, > Pit > Yeah. I just thought I would post it. Mostly equivalent to what he was doing but quite different in what tools were used. Yours is much more elegant either way. If I was serious about the prime numbers I would have built a quadratic sieve of some sort. I also hate for-loops (in most cases). ;) Brian.