Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site utcsrgv.UUCP Path: utzoo!utcsrgv!info-mac From: info-mac@utcsrgv.UUCP (info-mac) Newsgroups: ont.micro.mac Subject: Eratosthenes sieve Message-ID: <4036@utcsrgv.UUCP> Date: Thu, 26-Apr-84 01:51:42 EST Article-I.D.: utcsrgv.4036 Posted: Thu Apr 26 01:51:42 1984 Date-Received: Thu, 26-Apr-84 04:11:14 EST Sender: peterr@utcsrgv.UUCP Organization: CSRG, University of Toronto Lines: 47 Date: 22 Apr 1984 13:04:56-PST From: Bob Albrightson To: info-mac@sumex-aim Subject: Eratosthenes sieve Here is a version of the sieve program that should run faster. If the implementaion on the mac is correct then this set should use only 2k bytes. There is also a possibility that the mac pascal will only handle sets in chunks of one or two words in length (16 or 32 set elements). If that is the case then more coding will be required to handle the sieve 16 or 32 elements at a time in an array. I hope somebody tries this out. program eratosthenes(output); const sievemax = 16383; type range = 0..sievemax; var i,j: integer; sieve: set of range; begin sieve := [1..sievemax]; i := 2; writeln(output, 1); (* kludge, but a small one *) while i <= sievemax do begin writeln(output, i); j := i*2; while j < sievemax do begin sieve := sieve - [j]; j := j + i end; i := succ(i); while (not (i in sieve)) and (i <= sievemax) do i := succ(i) end end. -bob (BOB@WASHINGTON)