Created
July 6, 2020 19:29
-
-
Save remi-bruguier/53f0d7c0cc89a7350fcebfd468084569 to your computer and use it in GitHub Desktop.
Trouvez une chaîne de 9 caractères (seulement constituées des lettres "acdegilmnoprstuw") telle que hash(la_string) soit 956446786872726 si le hash est défini par le code suivant :
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
/* Int64 hash (String s) { | |
Int64 h = 7 | |
String letters = "acdegilmnoprstuw" | |
for(Int32 i = 0; i < s.length; i++) { | |
h = (h * 37 + letters.indexOf(s[i])) | |
} | |
return h | |
} */ | |
const kalAsh = (hashed:number) : string => { | |
let result:string[] = []; | |
let index = hashed; | |
while(hashed!==7){ | |
while(index % 37 !== 0){ | |
index--; | |
} | |
result.unshift(letters[hashed - index]) | |
hashed = index /= 37; | |
} | |
return result.join('') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment