123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- define MAX 1000
- define NS 10
- SIEVE ==
- [
- i = 0 ->
- console!2;
- n : integer := 3;
- *[
- n < MAX -> sieve[1]!n; n := n + 2
- ]
- []
- i = NS + 1 ->
- n : integer;
- *[
- sieve[NS]?n -> console!n
- ]
- []
- (i/=0) & (i/=NS + 1) ->
- p, mp : integer;
- sieve [i-1]?p;
- console!p;
- mp := p;
- m : integer;
- *[
- sieve[i-1]?m ->
- * [ m > mp -> mp := mp + p];
- [
- m = mp -> skip
- []
- m < mp -> sieve[i+1]!m
- ]
- ]
- ]
- MAIN ==
- [
- sieve [i:0..NS + 1] :: SIEVE
- ||
- console ::
- n : integer;
- *[
- (i:0..NS + 1) sieve[i]?n -> print (n + "\n")
- ]
- ]
|