Method: CrossedDesigns.cross
- Defined in:
- lib/datafarming/cross.rb
.cross(inputs, idx = 0, tmp = [], solution = []) ⇒ Object
The “cross” method creates a large combinatorial design by crossing all combinations of individual smaller designs. It uses recursion to do so because we don’t know how many designs there may be in the input set.
The method takes an array of arrays, where each sub-array contains a single component design, and kicks off the recursive build process.
10 11 12 13 14 15 16 17 |
# File 'lib/datafarming/cross.rb', line 10 def self.cross(inputs, idx = 0, tmp = [], solution = []) if idx >= inputs.size solution << tmp else inputs[idx].each { |dp| cross(inputs, idx + 1, tmp + dp, solution) } end solution end |