Skip to content

Instantly share code, notes, and snippets.

@fomkin
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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