Sha256: 9110085a45a6ec17702d863201f4a058f32b9741638d2ee74ee2d8653e327127

Contents?: true

Size: 1.12 KB

Versions: 3

Compression:

Stored size: 1.12 KB

Contents

Rule Main
  output '*.prime'
  param $MAX := 20
Flow
  rule CurrentNumber.params({NUM: 2})
  rule Sieve.params({MAX: $MAX, NUM: 2})
End

Rule Sieve
  input '{$NUM}.current'
  input '*.not_prime'.all or null
  output '*.prime'
  param $MAX
  param $NUM
Flow
  if $NUM <= $MAX
    if $*.include?($NUM.as_string).not
      rule CreateNotPrimeAll.params({MAX: $MAX, NUM: $NUM})
      rule CreatePrime.params({NUM: $NUM})
    else
      rule CurrentNumber.params({NUM: $NUM + 1})
    end
    rule Sieve.params({MAX: $MAX, NUM: $NUM + 1})
  end
End

Rule CurrentNumber
  output '{$NUM}.current'
  param $NUM
Action
  touch {$NUM}.current
End

Rule CreateNotPrimeAll
  output '*.not_prime'
  output '{$NUM + 1}.current'
  param $MAX
  param $NUM
  param $i := 2
Flow
  if $NUM * ($i + 1) <= $MAX
    rule CreateNotPrimeAll.params({MAX: $MAX, NUM: $NUM, i: $i + 1})
  end
  rule CreateNotPrime.params({NUM: $NUM * $i})
  rule CurrentNumber.params({NUM: $NUM + 1})
End

Rule CreateNotPrime
  output '{$NUM}.not_prime'
  param $NUM
Action
  touch {$NUM}.not_prime
end

Rule CreatePrime
  output '{$NUM}.prime'
  param $NUM
Action
  touch {$NUM}.prime
End

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pione-0.1.2 example/SieveOfEratosthenes/SieveOfEratosthenes.pione
pione-0.1.1 example/SieveOfEratosthenes/SieveOfEratosthenes.pione
pione-0.1.0 example/SieveOfEratosthenes/SieveOfEratosthenes.pione