183c5bae38
FossilOrigin-Name: d2b8467883db80cb179089e1db1b1ed4dff1f11b4bee7086ee46d83f3ee0136e
24 lines
418 B
Forth
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
|
|
````
|