Permutations: Difference between revisions
Content added Content deleted
(→{{header|Scala}}: Simplify collections library example) |
|||
Line 4,451: | Line 4,451: | ||
=={{header|Scala}}== |
=={{header|Scala}}== |
||
There is a built-in function that |
There is a built-in function in the Scala collections library, that is part of the language's standard library. The permutation function is available on any sequential collection. It could be used as follows given a list of numbers: |
||
<lang scala>List( |
<lang scala>List(1, 2, 3).permutations.foreach(println)</lang> |
||
{{out}} |
{{out}} |
||
⚫ | |||
List( |
List(1, 2, 3) |
||
List( |
List(1, 3, 2) |
||
List( |
List(2, 1, 3) |
||
List( |
List(2, 3, 1) |
||
List( |
List(3, 1, 2) |
||
⚫ | |||
The following function returns all the unique permutation of a list: |
The following function returns all the unique permutation of a list: |