Skip to content

Instantly share code, notes, and snippets.

@edueo
Last active January 31, 2018 14:30
Show Gist options
  • Save edueo/1e5bba1eaadac6e6f244c635b69750df to your computer and use it in GitHub Desktop.
Save edueo/1e5bba1eaadac6e6f244c635b69750df to your computer and use it in GitHub Desktop.
clever_algorithm

Clever Algorithm

Find wheter or not 2 words are anagrams

  • Map each of 26 english characters (A,B,C,D ... Z) to a primer number
  • Then multiply the char of each word
  • Two words are anagrams if their products are the same
E.g: F(A) = 2, F(E) = 5, F(R)=7

F(ARE) = 2*5*7 = 70
F(EAR) = 5*2*7 = 70
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment