Modify it to show u what ur problem is

until primes[currentNum]
     p currentNum
     p primes[currentNum]
     currentNum += 2
end



On Jul 24, 2009, at 4:27 PM, Lloyd Linklater <lloyd / 2live4.com> wrote:

> I am writing a little thing to find all the prime numbers to a  
> million.
> I got it to work this way:
>
> highestPrime = 1_000_000
> primes = Array.new(highestPrime, true)
>
> currentNum = 3
> while currentNum < highestPrime do
>  (currentNum*currentNum).step(highestPrime, currentNum * 2) { |i|
> primes[i] = false }
>  currentNum += 2
>  while primes[currentNum] == false do
>    currentNum += 2
>  end
> end
>
> I am unhappy with using currentNum += 2 twice.  I very much want to
> write something like this:
>
> while currentNum < highestPrime do
>  (currentNum*currentNum).step(highestPrime, currentNum * 2) { |i|
> primes[i] = false }
>  currentNum += 2 until primes[currentNum] == true
> end
>
> but that just hangs the program.  What am I missing?
> -- 
> Posted via http://www.ruby-forum.com/.
>