Skip to content

Instantly share code, notes, and snippets.

@DiveInto
Created September 15, 2013 14:39
Show Gist options
  • Save DiveInto/6571329 to your computer and use it in GitHub Desktop.
Save DiveInto/6571329 to your computer and use it in GitHub Desktop.
compute all permutations of a string
object per extends App{
def permutations(str: String):List[String] = {
if(str.size == 0)
List("")
else{
val res = {
for{c <- str
per <- permutations(str.replaceFirst(c.toString, ""))
}yield c + per
}
▫▫
res.toList
}
}
val res = permutations("abc")
res.foreach(println)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment