Function permutator::get_cartesian_for
source · [−]Expand description
Get a cartesian product at specific location.
If objects
is [1, 2, 3] and degree is 2 then
all possible result is [1, 1], [1, 2], [1, 3],
[2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3]
Parameters
objects
is a slice of an object.degree
is a degree of cartesian size.i
is a specific location to get a combination.
Examples
use permutator::get_cartesian_for;
let nums = [1, 2, 3];
get_cartesian_for(&nums, 2, 0); // Return Ok([1, 1])
get_cartesian_for(&nums, 2, 3); // Return Ok([2, 1])
get_cartesian_for(&nums, 2, 8); // Return Ok([3, 3])
get_cartesian_for(&nums, 2, 9); // Return Err("Parameter `i` is out of bound")
get_cartesian_for(&nums, 4, 0); // Return Err("Parameter `degree` cannot be larger than size of objects")