Steven Schveighoffer wrote:
A comment to explain the representation of the array may be good.
Well, I did add your explanation to the bugzilla report! Thanks.
On Fri, 14 May 2010 19:37:58 -0400, Walter Bright
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 t
Walter Bright wrote:
bearophile wrote:
Walter Bright:
Are you sure? What's the mistake in the code?
This is the code in the Overview, it prints 1899:
http://codepad.org/lzRtggEL
This is the code I have suggested in bugzilla, it prints 1027:
http://ideone.com/D9ZqQ
Wolfram Alpha says they
Ary Borenszweig:
> A small observation: count +=1 is performed for i = 0, hmmm...
It lacks unit tests. A basic unit testing can catch that bug.
Recently I have ready a quote: "If it has no unit tests then it's broken".
Experience shows me that this is more often true than false.
Bye,
bearophile
Walter Bright wrote:
bearophile wrote:
Walter Bright:
Are you sure? What's the mistake in the code?
This is the code in the Overview, it prints 1899:
http://codepad.org/lzRtggEL
This is the code I have suggested in bugzilla, it prints 1027:
http://ideone.com/D9ZqQ
Wolfram Alpha says they ar
bearophile wrote:
Walter Bright:
Are you sure? What's the mistake in the code?
This is the code in the Overview, it prints 1899:
http://codepad.org/lzRtggEL
This is the code I have suggested in bugzilla, it prints 1027:
http://ideone.com/D9ZqQ
Wolfram Alpha says they are 1027 (I have left ou
Walter Bright:
> Are you sure? What's the mistake in the code?
This is the code in the Overview, it prints 1899:
http://codepad.org/lzRtggEL
This is the code I have suggested in bugzilla, it prints 1027:
http://ideone.com/D9ZqQ
Wolfram Alpha says they are 1027 (I have left out the last number be
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 c
Thanks!
R.Tenton:
> That would be nice.
http://d.puremagic.com/issues/show_bug.cgi?id=4164
That would be nice.
R.Tenton:
> Or is this the wrong place to ask?
The right place to report errors in the docs is the bugzilla...
But if you don't want to subscribe some people here can do it for you.
Bye,
bearophile
The sieve algorith was not my problem. I wanted to point out that
the example is totally screwed up, so it would be corrected.
Or is this the wrong place to ask?
D2 code, the 8191 too is counted:
import std.stdio: writeln;
int sieve(int m) {
auto isPrime = new bool[m + 1];
isPrime[] = true;
int count;
foreach (i; 2 .. isPrime.length) {
if (isPrime[i]) {
count++;
for (int k = i * 2; k < isPrime.length; k +=
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]!
What is the outermost for loop good for?
This example is just
15 matches
Mail list logo