Menu

[r350]: / XSIEVE.MPL  Maximize  Restore  History

Download this file

25 lines (18 with data), 440 Bytes

// ERATOSTHENES SIEVE PRIME NUMBER GENERATOR
// CONVERTED FROM GPASCAL

##LIBHDR

.SIZE     : 1001
.PERLINE  : 10

.FLAGS=%.SIZE I=0 PRIME=0 K=0 COUNT=0

.() [
  MSET(.FLAGS,.TRUE,.SIZE);
  I=0; I<.SIZE @ [
    .FLAGS%I ? [
      K=I+(PRIME=<<I+3); 
      K<.SIZE @ [ .FLAGS%K=.FALSE; K+=PRIME ];
      WRITEF("%I5%S",PRIME,++COUNT\.PERLINE ? "" : "*N")
    ];
    ++I
  ];
  WRITEF("*N*N%N PRIMES*N*N",COUNT);
0]

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.