RosettaCodeData/Task/Primality-by-trial-division/Forth/primality-by-trial-division.fth
2015-02-20 00:35:01 -05:00

11 lines
309 B
Forth

: prime? ( n -- f )
dup 2 < if drop false
else dup 2 = if drop true
else dup 1 and 0= if drop false
else 3
begin 2dup dup * >=
while 2dup mod 0=
if 2drop false exit
then 2 +
repeat 2drop true
then then then ;