Created
November 7, 2012 10:47
-
-
Save jkdeveyra/4030815 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
def sentenceAnagrams(sentence: Sentence): List[Sentence] = { | |
def subSentence(occ: Occurrences): List[Sentence] = { | |
if (occ.isEmpty) List(List()) | |
else | |
for { | |
x <- combinations(occ) | |
y <- dictionaryByOccurrences(x) | |
z <- subSentence(subtract(occ, x)) | |
} yield y :: z | |
} | |
subSentence(sentenceOccurrences(sentence)) | |
} |
If I would have had a million guesses I wouldn't have found that...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think that dictionaryByOccurrences.get(x) getOrElse (List()) at y, like in https://gist.github.com/valtih1978/5983b7620798beeda317, is better in place of filtering at x both neatness and performansewise.