home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD2.mdf
/
c
/
interpre
/
proxy
/
sieve.prx
< prev
next >
Wrap
Text File
|
1994-03-03
|
663b
|
21 lines
eos="eos";
ch1=channel();
ch2=channel();
task gen(out,n;i) {
i=2;
while(i<=n) {
out!i;
i=i+1;}
out!eos;};
task sink(inp;x) {inp?x;while(x!=eos) {print x;inp?x;}};
task sieve(inp,out;x,y,succ) {inp?x;
if(x==eos) {out!eos;skip;}
succ = channel();
start sieve(succ,out);
while(true)
{inp?y;
if(y==eos) {out!x;succ!eos;skip;}
if(y%x!=0) succ!y;}};
task main(n) {start gen(ch1,n);start sieve(ch1,ch2);start sink(ch2);};
end