Skip to content

Instantly share code, notes, and snippets.

@jkdeveyra
Created November 7, 2012 10:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jkdeveyra/4030815 to your computer and use it in GitHub Desktop.
Save jkdeveyra/4030815 to your computer and use it in GitHub Desktop.
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))
}
@ZilvinasKucinskas
Copy link

Pretty solution

@jamerlan
Copy link

I really hate these combination tasks

@seekerlee
Copy link

awesome! Just need to replace this line:
x <- combinations(occ) filter dictionaryByOccurrences.contains

@valtih1978
Copy link

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.

@Spike2050
Copy link

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