Paste: ir

Author: prunedtree
Mode: factor
Date: Fri, 9 Jan 2009 16:42:12
Plain Text |
IR: nsieve ( int bool[] -- int )
[ [ >m ] [ >isPrimt ] bi*
  2 m> [a,b] [ true swap isPrime> set-at ] for
  0 >count
  2 m> [a,b] [ >i
    i> isPrime> at 
    [ 
      i> dup + m> i> <range> [ false swap isPrime> set-at ] for
      count> ++ 
    ] when
  ] for
  count>
] ;

static int nsieve(int m, boolean[] isPrime)
   {
      for (int i=2; i <= m; i++) isPrime[i] = true;
      int count = 0;

      for (int i=2; i <= m; i++) {
         if (isPrime[i]) {
            for (int k=i+i; k <= m; k+=i) isPrime[k] = false;
            count++;
         }
      }
      return count;
   }

New Annotation

Summary:
Author:
Mode:
Body: