% $Id: sieve.slang,v 1.0 2003/01/03 12:51:00 dada Exp $
% http://dada.perl.it/shootout/
%
% contributed by John E. Davis

define main()
{
   variable NUM = integer (__argv[1]);
   variable flags = Int_Type[8192 + 1];
   loop (NUM)
     {
        flags[*] = 1;
        variable count = 0;
    _for (2, 8192, 1)
      {
         variable i = ();
         if (flags[i])
           {
#iftrue
          flags[[i+i:8192:i]] = 0;
#else
          _for (i+i, 8192, i)
            {
               variable j = ();
               flags[j] = 0;
            }
#endif
          count++;
           }
      }
     }
   
   vmessage ("Count: %d", count);
}
main();