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 works on any sequential collection. It could be used as follows given a List of symbols:
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('a, 'b, 'c).permutations foreach println</lang>
<lang scala>List(1, 2, 3).permutations.foreach(println)</lang>

{{out}}
{{out}}

<pre>List('a, 'b, 'c)
List('a, 'c, 'b)
List(1, 2, 3)
List('b, 'a, 'c)
List(1, 3, 2)
List('b, 'c, 'a)
List(2, 1, 3)
List('c, 'a, 'b)
List(2, 3, 1)
List('c, 'b, 'a)</pre>
List(3, 1, 2)
List(3, 2, 1)



The following function returns all the unique permutation of a list:
The following function returns all the unique permutation of a list: