mirror of
https://github.com/remko/waforth
synced 2025-01-28 07:58:31 +01:00
21 lines
296 B
Forth
21 lines
296 B
Forth
: prime? HERE + C@ 0= ;
|
|
: composite! HERE + 1 SWAP C! ;
|
|
|
|
: sieve
|
|
HERE OVER ERASE
|
|
2
|
|
BEGIN
|
|
2DUP DUP * >
|
|
WHILE
|
|
DUP prime? IF
|
|
2DUP DUP * DO
|
|
I composite!
|
|
DUP +LOOP
|
|
THEN
|
|
1+
|
|
REPEAT
|
|
DROP
|
|
1 SWAP 2 DO I prime? IF DROP I THEN LOOP .
|
|
;
|
|
|
|
: main 10000 sieve ;
|