Skip to content

Instantly share code, notes, and snippets.

@fomkin
Last active August 29, 2015 14:16
Show Gist options
  • Save fomkin/4eb5460207ab1773bd80 to your computer and use it in GitHub Desktop.
Save fomkin/4eb5460207ab1773bd80 to your computer and use it in GitHub Desktop.
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