Skip to content

Instantly share code, notes, and snippets.

@remi-bruguier
Created July 6, 2020 19:29
Show Gist options
  • Save remi-bruguier/53f0d7c0cc89a7350fcebfd468084569 to your computer and use it in GitHub Desktop.
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 :
/* 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