flow = "composites"

[[input]]
name = "limit"
type = "number"

# Generate a sequence of divisors from 2, upto sqrt(limit) (e.g. limit = 9, 2..3)
[[process]]
source = "lib://flowstdlib/math/sqrt"
#
[[connection]]
from = "input/limit"
to = "sqrt"
[[process]]
alias = "divisors"
source = "lib://flowstdlib/math/sequence"
input.start = {once =  2}
input.step = {once =  1}
[[connection]]
from = "sqrt"
to = "divisors/limit"

## generate a sequence of composites - i.e. All the non-primes upto the limit

# start at 2 x divisor - no point in generating composites from the divisor itself
# e.g. if start = 2, first composite will be 4
[[process]]
source = "lib://flowstdlib/math/multiply"
input.i2 = {always =  2}
[[connection]]
from = "divisors/sequence"
to = "multiply/i1"
[[connection]]
from = "multiply"
to = "composite-sequence/start"

# the step each time will be the divisors. e.g. 2, 3
[[connection]]
from = "divisors/sequence"
to = "composite-sequence/step"

[[connection]]
from = "input/limit"
to = "composite-sequence/limit"

# generate the sequence-of-sequences of composites as an output
# [start = 4, step = 2, limit = 9] -> [4, 6, 8]
# [start = 6, step = 3, limit = 9] -> [6, 9]
[[process]]
alias = "composite-sequence"
source = "lib://flowstdlib/math/sequence"
[[output]]
name = "composites"
type = "number"
[[connection]]
from = "composite-sequence/sequence"
to = "output/composites"