combinat::permute --
permutations of a list
Introductioncombinat::permute(list) computes all the reorderings of
the given list list.
combinat::permute(n) computes all the reorderings of
the list [1,2,...,n].
Call(s)combinat::permute(n)
combinat::permute(list)
combinat::permute(list,Duplicate)
Parametersn |
- | a nonnegative integer |
list |
- | a list |
OptionsDuplicate |
- | The result may contain identical lists if there are
duplicates in the given list list. |
ReturnsA list of type DOM_LIST containing every reordered
list as an element.
DetailsDuplicate,
all lists in the result are distinct.
Option: Duplicate
Example
1There are exactly two ways of ordering two elements.
>> combinat::permute([a,b])
[[a, b], [b, a]]
Example
2An integer argument n is equivalent to the list of the first n integers.
>> combinat::permute(3)
[[2, 3, 1], [3, 2, 1], [1, 3, 2], [3, 1, 2], [1, 2, 3],
[2, 1, 3]]
Example
3By default, one gets all distinct reorderings.
>> combinat::permute([a,a,b])
[[a, b, a], [b, a, a], [a, a, b]]
Example
4But if one wants to get a list with duplicated reordered entries, this is also possible.
>> combinat::permute([a,a,b],Duplicate)
[[a, b, a], [b, a, a], [a, b, a], [b, a, a], [a, a, b],
[a, a, b]]
Example
5Sets are not allowed as an argument.
>> combinat::permute({3,4})
Error: argument must be a list or a non-negative integer! [com\
binat::permute]
combinat::permute().