Skip to content

Commit

Permalink
non-primes
Browse files Browse the repository at this point in the history
  • Loading branch information
lpetit-yseop committed Apr 16, 2014
1 parent 1dba0bd commit e3e5f6a
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions non-primes.oz
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
% non primes
declare
fun {Prod X Stop}
if X>Stop then nil
else X|{Prod X+1 Stop}
end
end

declare
fun {Filter Xs C}
case Xs of nil then nil
[] X|Xr then
if (X mod C)==0 then
{Filter Xr C}
else
X|{Filter Xr C}
end
end
end

declare
fun {Sieve Xs}
case Xs of nil then nil
[] X|Xr then
X|{Sieve thread {Delay 1000} {Filter Xr X} end}
end
end

declare
fun {NotPrime S1 S2}
case S2
of nil then S1
[] X2|X2r then
case S1
of nil then nil
[] X1|X1r then
if X1==X2 then
{NotPrime X1r X2r}
else
X1|{NotPrime X1r S2}
end
end
end
end

local P S NP in
P=thread {Prod 2 100} end
S=thread {Sieve P} end
NP=thread {NotPrime P S} end
{Browse NP}
end

0 comments on commit e3e5f6a

Please sign in to comment.