# $Id: sieve.pliant,v 1.0 2002/02/06 15:17:00 dada Exp $
# http://dada.perl.it/shootout/

module "/pliant/language/context.pli"

gvar Array:Int flags
gvar Int count
gvar Int i
gvar Int k
gvar Str s_n := cast ((pliant_script_args translate Address 1) map CStr) Str
if (s_n parse (gvar Int n))
  flags:size := 8192
  while n > 0
    count := 0
    for (i) 0 (flags:size)
      flags:i := 1
    for (i) 2 8192
      if flags:i = 1
        for k i+i 8192 step i
          flags:k := 0
        count := count + 1
    n := n - 1
  console "Count: " count eol
else
  console "usage: nestedloop.pli <number>" eol