def permutations[T]: List[T] => Traversable[List[T]] = {
case Nil => List(Nil)
case xs => {
for {
(x, i) <- xs.zipWithIndex
ys <- permutations(xs.take(i) ++ xs.drop(1 + i))
} yield {
x :: ys
}