Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.