Created
December 10, 2009 19:11
-
-
Save bmjames/253565 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
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