От: | avpavlov | ||
Дата: | 12.02.09 15:30 | ||
Оценка: |
def permutations[T](list:List[T]):List[List[T]] = list match {
case List() => List()
сase List(a) => List(List(a))
case _ => list.flatMap(item => permutations(list.filter(_ != item)).map(permutation => item :: permutation))
}
println(permutations(List(1,2,3,4)).mkString("\n"))