primes/primes.sml

31 lines
578 B
Standard ML
Raw Permalink Normal View History

2011-03-08 08:01:27 +01:00
(* Standard ML version of a Prime Number Finder
haplo@mindstab.net *)
fun check i cnt max = if i > max
then
1
else
if cnt mod i = 0 then
0
else
check (i+2) cnt max
fun ploop cnt max sq sqm =
if cnt > max then
print ""
else
if cnt >= sqm then
ploop cnt max (sq+1) ((sq+1)*(sq+1))
else
(if ((check 3 cnt sq) <> 0) then
(print (Int.toString(cnt));
print("\n") )
else
print ""
; ploop (cnt+2) max sq sqm)
fun primes max =
(print "\n"; ploop 3 max 2 4);
(* autotest call will be inserted here via sed *)