Skip to content

Instantly share code, notes, and snippets.

@silveira
Last active January 31, 2018 16:37
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 silveira/1bb2756401f5dfe6f878810b5f17817b to your computer and use it in GitHub Desktop.
Save silveira/1bb2756401f5dfe6f878810b5f17817b to your computer and use it in GitHub Desktop.
f receives a lower case string word and returns a product of primes that is the same for anagrams of that word
// https://twitter.com/fermatslibrary/status/958700402647674880
function f(word) {
var primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,73, 79, 83, 89, 97, 101];
var product = 1;
for (var i=0; i<word.length; i++) {
product *= primes[word[i].charCodeAt(0)-97];
}
return product;
}
/*
f('a') // 2
f('ab') // 6
f('ba') // 6
f('are') // 1342
f('ear') // 1342
f('undefinability') // 2513393075500633600
f('unidentifiably') // 2513393075500633600
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment