Example in the overview

Steven Schveighoffer schveiguy at yahoo.com
Fri May 14 20:34:59 PDT 2010


On Fri, 14 May 2010 19:37:58 -0400, Walter Bright  
<newshound1 at digitalmars.com> wrote:

> R.Tenton wrote:
>> At the very bottom of http://digitalmars.com/d/2.0/overview.html
>> there is an example implementation of the Eratosthenes' sieve.
>> That code is broken! It counts 1899 prime numbers, while there are only  
>> 1028
>> primes in the interval [1,8191]!
>
> Are you sure? What's the mistake in the code?

I think the issue is that the expectation is that array index x represents  
the number x.  But it doesn't seem that way.

the i + i + 3 is very odd indeed.

If we consider each index, it means the first element represents 0 + 0 + 3  
= 3;
The second element represents 1 + 1 + 3 = 5;
The third element represents 2 + 2 + 3 = 7;

So it looks like the numbers represented by the array actually go from 3  
to (8190 + 8190 + 3) or 16383.

According to Wolfram Alpha, the number of primes in that list is 1899

http://www.wolframalpha.com/input/?i=primes+in+3+..+16383

A comment to explain the representation of the array may be good.

-Steve


More information about the Digitalmars-d-learn mailing list