Created
July 18, 2018 01:24
-
-
Save sdbruder/8ced5b240110dfd55b1dfacb186dc4a0 to your computer and use it in GitHub Desktop.
question
This file contains hidden or 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
function strUnhash(h) | |
{ | |
str = ""; | |
letters = "acdfgilmnoprstuw"; | |
while(h>23) { | |
c = h % 23; | |
h = (h-(h%23))/23; // or a simpler Math.floor(h / 23) as h is always positive; | |
str = letters[c] + str; | |
} | |
return str; | |
} | |
function strHash(s) | |
{ | |
hash = 7; | |
letters = "acdfgilmnoprstuw"; | |
for(i = 0; i < s.length; i++) | |
{ | |
hash = (hash * 23 + letters.indexOf(s[i])); | |
} | |
return hash; | |
} | |
console.log(strHash("tortilla")); | |
console.log(strUnhash(593846452632)); | |
console.assert("tortilla" == strUnhash(strHash("tortilla"))); | |
console.log(strUnhash(292681030017238)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment