Skip to content

Instantly share code, notes, and snippets.

@wfaler
Created July 5, 2013 15:41
Show Gist options
  • Save wfaler/5935382 to your computer and use it in GitHub Desktop.
Save wfaler/5935382 to your computer and use it in GitHub Desktop.
WordAbbrevationPermutations.scala
object WordAbbrevationPermutations extends App{
val list = "FOOO" :: "BAR" :: "BAZ" :: Nil //FBB, FBA, FBZ, FAB..
abbrevations(list).foreach(println)
def abbrevations(list: List[String]): List[String] ={
list match{
case head :: Nil => head.map(_.toString).toList
case head :: tail => head.flatMap(c => abbrevations(tail).map(s => c.toString + s)).toList
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment