Created
August 14, 2017 13:10
-
-
Save pfcoperez/348efdfbef518274ad11d84f6b79ec7b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@tailrec | |
def permutations[T](alphabet: Set[T], s: Seq[Seq[T]] = Seq(Seq.empty[T])): Seq[Seq[T]] = | |
if(s.head.size == alphabet.size) s else { | |
val updatedSolutions = for { | |
partial <- s | |
chosen <- (alphabet -- partial) | |
} yield chosen +: partial | |
permutations(alphabet, updatedSolutions) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment