get all possible permutations of the elements in given collection
Parameters
permutate collection :block
Attributes
by
:integer
define size of each set
repeated
allow for permutations with repeated elements
count
just count the number of permutations
Returns
:block
Examples
copy
permutate [A B C]
; => [[A B C] [A C B] [B A C] [B C A] [C A B] [C B A]]
permutate.repeated [A B C]
; => [[A A A] [A A B] [A A C] [A B A] [A B B] [A B C] [A C A] [A C B] [A C C] [B A A] [B A B] [B A C] [B B A] [B B B] [B B C] [B C A] [B C B] [B C C] [C A A] [C A B] [C A C] [C B A] [C B B] [C B C] [C C A] [C C B] [C C C]]
copy
permutate.by:2 [A B C]
; => [[A B] [A C] [B A] [B C] [C A] [C B]]
permutate.repeated.by:2 [A B C]
; => [[A A] [A B] [A C] [B A] [B B] [B C] [C A] [C B] [C C]]
permutate.repeated.by:3 [A B]
; => [[A A A] [A A B] [A B A] [A B B] [B A A] [B A B] [B B A] [B B B]]
copy
permutate.count [A B C]
; => 6
permutate.count.repeated.by:2 [A B C]
; => 9