From: Joe Van Dyk Date: 2005-06-27T14:57:22+09:00 Subject: Re: I saw the beauty of Ruby Re: 1. Ruby result: 101 seconds , 2. Java result:9.8 seconds, 3. Perl result:62 seconds On 6/26/05, jzakiya@mail.com wrote: > > class Integer > > def primes > > f=2 > > p=[] if self <2 > > p=[2] if self >=2 > > 3.step(self, 2) do |i| > > r = Math.sqrt(i).to_i > > p.each { |f| break if (i%f).zero? or f > r} > > p.push(i) if (i%f).nonzero? > > end # end the do block > > return p > > end > > end > > To make shorter/clearer(?) replace > > p=[] if self <2 > p=[2] if self >=2 > > with > > p = self > 1 ? [2] : [] I vote for shorter, not clearer.