Skip to content

Instantly share code, notes, and snippets.

@bmjames
Created December 10, 2009 19:11
Show Gist options
  • Save bmjames/253565 to your computer and use it in GitHub Desktop.
Save bmjames/253565 to your computer and use it in GitHub Desktop.
import scala.io.Source
val words = for {
line <- Source.fromFile("/usr/share/dict/words").getLines
word = line.trim.toLowerCase
if word.length <= 6
} yield word
val sixLetterWords = words filter { _.length == 6 }
val candidateParts = words filter { _.length < 6 }
val wordPairs = for {
part <- candidateParts
remainders = sixLetterWords filter {_ startsWith part} map {_ drop part.length}
partner <- remainders filter { candidateParts contains }
} yield (part, partner)
wordPairs foreach { pair => println(pair._1+"+"+pair._2) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment