ary.repeated_permutation(n) { |p| block } â ary
ary.repeated_permutation(n) â Enumerator
ary.repeated_permutation(n) â Enumerator
Instance Public methods
When invoked with a block, yield all repeated permutations of length
n
of the elements of the array, then return the array itself.
The implementation makes no guarantees about the order in which the repeated permutations are yielded.
If no block is given, an Enumerator is returned instead.
Examples:
a = [1, 2] a.repeated_permutation(1).to_a #=> [[1], [2]] a.repeated_permutation(2).to_a #=> [[1,1],[1,2],[2,1],[2,2]] a.repeated_permutation(3).to_a #=> [[1,1,1],[1,1,2],[1,2,1],[1,2,2], # [2,1,1],[2,1,2],[2,2,1],[2,2,2]] a.repeated_permutation(0).to_a #=> [[]] # one permutation of length 0
Please login to continue.