Last active
August 29, 2015 14:16
-
-
Save fomkin/4eb5460207ab1773bd80 to your computer and use it in GitHub Desktop.
This file contains 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
val input = Vector("стационар", "соратница", "ватерполистка", "равновесие", "спаниель", | |
"кильватер", "полковник", "нерасторжимость", "Вениамин", "австралопитек", "своенравие", | |
"внимание", "апельсин", "вертикаль", "старорежимность", "клоповник", | |
"пенсионерка", "покраснение") | |
def anagrams(xs: Seq[String]): Seq[Seq[String]] = { | |
def wSum(s: String) = { | |
val ls = s.toLowerCase | |
val l = ls.length | |
(0 until l).map(ls.charAt).sum | l << 16 | |
} | |
xs.groupBy(wSum).values.toSeq | |
} | |
anagrams(input) foreach println |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment