Skip to content

Instantly share code, notes, and snippets.

@r-wheeler
Created January 11, 2015 00:21
Show Gist options
  • Save r-wheeler/ebe6e648d363e8b2efdd to your computer and use it in GitHub Desktop.
Save r-wheeler/ebe6e648d363e8b2efdd to your computer and use it in GitHub Desktop.
DailyProgrammer[2/13/12] - Anagram
//http://www.reddit.com/r/dailyprogrammer/comments/pnhtj/2132012_challenge_5_intermediate/
import scala.io.Source
val wordList = Source.fromURL("http://www.joereynoldsaudio.com/enable1.txt").getLines()
def findAnagrams(words: Iterator[String]) = {
val dd = words.foldLeft(Map.empty[String, List[String]]) {
case (acc, x) => acc + (x.sorted -> (x :: acc.getOrElse(x.sorted,Nil)))
}.values
.filter(_.length > 1)
.foreach(println)
}
findAnagrams(wordList)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment