retroforth/example/Primes.forth
crc 183c5bae38 Initial checkin (from 58fa921 in the old git repo)
FossilOrigin-Name: d2b8467883db80cb179089e1db1b1ed4dff1f11b4bee7086ee46d83f3ee0136e
2017-10-16 16:09:39 +00:00

24 lines
418 B
Forth

This is a quick and dirty way to find prime numbers in a set.
````
{{
#2 'last var<n>
:extract (s-s)
[ @last dup-pair eq?
[ drop-pair TRUE ]
[ mod n:-zero? ] choose ] set:filter ;
---reveal---
:get-primes (s-s)
#2 !last
dup fetch [ extract &last v:inc ] times ;
}}
````
And a test:
````
here
#7500 ,
#2 #7502 [ dup , n:inc ] times drop
get-primes [ putn sp ] set:for-each
````