Skip to content

Instantly share code, notes, and snippets.

@notyy
Created March 3, 2012 15:21
Show Gist options
  • Save notyy/1966590 to your computer and use it in GitHub Desktop.
Save notyy/1966590 to your computer and use it in GitHub Desktop.
perm
def perm[T](ls: List[T]): List[List[T]] = ls match {
case Nil => List[Nil]
case xs => for{
(x,i) <- ls.zipWithIndex
(leftX,rightX) = xs.splitAt(i)
ys <- perm(leftX ++ rightX.tail)
} yield (x:: ys)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment