Last active
January 31, 2018 16:37
-
-
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
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
// 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