PPaste!

Home - All the pastes - Authored by Thooms

Raw version

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
  def sentenceAnagrams(sentence: Sentence): List[Sentence] = {

    def aux(occurrences: Occurrences): List[Sentence] = {
      val possibleWords = (combinations(occurrences) flatMap (dictionaryByOccurrences get)).flatten
//      val possibleWords = (occurrences flatMap (dictionaryByOccurrences get)).flatten
      Nil :: (for {
        word <- possibleWords
        rest <- aux(subtract(occurrences, wordOccurrences(word)))
      } yield word :: rest)
    }
    val occurrences = sentenceOccurrences(sentence)
    aux(occurrences)
  }