beginner needs help with sieve program

Maurice Castro <>
Mon Sep 4 02:00:08 CEST 2000


The Erastoshenes prime number sieve is an excelent starting problem for
Erlang ... in fact I set it as an exercise in my book. A sample solution
is provided.

	http://www.serc.rmit.edu.au/~maurice/erlbk/
	http://www.serc.rmit.edu.au/~maurice/erlbk/eg/choice/erasto.erl

This example delibarately does not use: funs, and many of the functions
provided in the modules. Although the provided functions are often
more efficient, they tend to distract from the learning process.

It turns out that it is the remove multiples routine that is at
fault ... from your comments it is clear that you have
already established this. My theory is that the problem is actually a problem 
in the 
algorithm not in the Erlang implemenation as the immediate cause of the 
problem is that remove multiples attempts to evaluate over the following 
arguments:

	T = [2197, 2201, 2203 | ...]
	H = 2183
	Next = 2184
	Num = 13

The algorithm is `unlucky' here as the value of H is exactly 13 more than
the value next. Hence the logic of the algorithm lets you down.

	Maurice Castro



More information about the erlang-questions mailing list