Last active
August 29, 2015 14:04
-
-
Save cscorley/61cc3adc7705ba847e89 to your computer and use it in GitHub Desktop.
Trello application puzzle in Python
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
letters = "acdegilmnoprstuw" | |
def hash(s): | |
h = 7 | |
for char in s: | |
h = h * 37 + letters.index(char) | |
return h | |
target = 910897038977002.0 | |
current = target | |
t = "" | |
while len(t) < 9: | |
for i, char in enumerate(letters): | |
if (current - i) % 37 == 0: | |
t += char | |
current = (current - i) / 37 | |
break | |
t = t[::-1] | |
print(t, hash(t)) | |
assert target == hash(t), 'hash("%s") == %d' % (t, hash(t)) |
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
# another, better solution | |
letters = "acdegilmnoprstuw" | |
def hash(s): | |
h = 7 | |
for char in s: | |
h = h * 37 + letters.index(char) | |
return h | |
target = 956446786872726 | |
current = target | |
t = "" | |
while len(t) < 9: | |
i = current % 37 | |
t += letters[i] | |
current = (current - i) / 37 | |
t = t[::-1] | |
print(t, hash(t)) | |
assert target == hash(t), 'hash("%s") == %d' % (t, hash(t)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment