The sieve of eratosthenes
forth
\ Sieve of Eratosthenes in Forth
\ Written by Rob Hoelz
\ To run: Load this file into a Forth interpreter, and call <limit> MAIN
VARIABLE LIMIT
: RANGE RECURSIVE 2DUP =
IF DROP
ELSE DUP -ROT 1- RANGE
THEN ;
: REMOVE RECURSIVE DUP DEPTH 3 - >
IF DROP
ELSE DUP 1+ PICK 2 PICK MOD 0=
IF DUP 1+ ROLL DROP REMOVE
ELSE 1+ REMOVE
THEN
THEN ;
: REMOVE.MULTIPLES 1 REMOVE ;
: GENERATE RECURSIVE DUP . DUP DUP * LIMIT @ >
IF DROP
ELSE REMOVE.MULTIPLES DROP GENERATE
THEN ;
: PRINT.PRIMES RECURSIVE DEPTH 0>
IF . PRINT.PRIMES
ELSE CR
THEN ;
: MAIN
LIMIT !
2 LIMIT @ RANGE GENERATE PRINT.PRIMES ;
stats
It is
Monday September 08, 2008 12:52 am
This page served 761 times
This page last modified: April 14, 2008 11:28 am
Your IP address is: 38.103.63.61
You are browsing using: CCBot/1.0 (+http://www.commoncrawl.org/bot.html)
You are browsing from: United States.
badcomputer.org's uptime: 00:52:31 up 39 days, 15:59, 2 users, load average: 0.01, 0.02, 0.00
local
home | unix stuff | dir2ogg | sneetchalizer | wmainfo | q&d guide to permissions | q&d guide to tar and gzip | code | MS rant | browser shootout | linux & iAudio X5 | photos | music | programming poetry | sieve of Eratosthenes | plea | rain | suffer | archive | about | recipes | compaqr3000 | sitemap
search
credits
This page, and all pages on this site were created and are maintained by Darren Kirby using valid XHTML 1.0 and CSS, and are ©copyright 2002 - 2008. The Penguin image was created by Tukka, and is used by permission. Inspiration for the look of this site was provided by Eric A. Meyer's CSS gallery. This website runs on Gentoo Linux. It is served by Apache. PHP and MySQL hold together the backend.