Anonymous user
Permutations: Difference between revisions
→{{header|Scala}}: Partial function using for-comprehension
(→{{header|Scala}}: Partial function using for-comprehension) |
|||
Line 4,465:
List(3, 1, 2)
List(3, 2, 1)
The following function returns all the unique permutation of a list:
<lang scala> def permutations[T]
for {
i <- 0 until xs.length
ys <- permutations(xs.take(i) ++ xs.drop(1 + i))
} yield {
xs(i) :: ys
}
}
}</lang>
=={{header|Scheme}}==
|