Skip to main content
4 of 9
added 21 characters in body; added 5 characters in body
Tom Gullen
  • 1.3k
  • 1
  • 8
  • 12

Javascript - 192 157 (78 without dictionary)

Ok some of these languages are a lot more flexibile than I thought! Anyway this is the longer way I guess, but a different technique at least.

Compressed

a=[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];function b(c){r=1;for(i=0;i<c.length;i++)r*=a[c[i].charCodeAt(0)-97];return r}

Then do:

alert(b("hello")==b("elloh"));

Expanded Code

// Define dictionary of primes
a = [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];

// Returns the unique ID of the word (order irrelevant)
function b(c) {
    r = 1;
    for (i = 0; i < c.length; i++)
        r *= a[c[i].charCodeAt(0) - 97];
    return r
}

alert(b("hello") == b("hlleo"));
Tom Gullen
  • 1.3k
  • 1
  • 8
  • 12