Documentation for routine
permutations assembled from the following types:
method permutations(--> Seq)
Any as a 1-item list and uses
List.permutations on it.
say Any.permutations; # OUTPUT: «(((Any)))␤»
multi sub permutations(Int() --> Seq)multi sub permutations(Iterable --> Seq)multi method permutations(List: --> Seq)
Returns all possible permutations of a list as a Seq of lists:
.say for <a b c>.permutations;# OUTPUT:# (a b c)# (a c b)# (b a c)# (b c a)# (c a b)# (c b a)
permutations treats all elements as unique, thus
(1, 1, 2).permutations returns a list of 6 elements, even though there are only three distinct permutations, due to first two elements being the same.
The subroutine form behaves the same as the method form, computing permutations from its first argument
$from is not an Iterable, coerces
$from to an
Int and picks from a Range constructed with
.say for permutations 3;# OUTPUT:# (0 1 2)# (0 2 1)# (1 0 2)# (1 2 0)# (2 0 1)# (2 1 0)