Flowdock
method

repeated_permutation

Importance_2
v1_9_3_392 - Show latest stable - 0 notes - Class: Array
repeated_permutation(p1) public

When invoked with a block, yield all repeated permutations of length n of the elements of ary, 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
Show source
Register or log in to add new notes.