Skip to content

Instantly share code, notes, and snippets.

@cscorley
Last active August 29, 2015 14:04
Show Gist options
  • Save cscorley/61cc3adc7705ba847e89 to your computer and use it in GitHub Desktop.
Save cscorley/61cc3adc7705ba847e89 to your computer and use it in GitHub Desktop.
Trello application puzzle in Python
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))
# 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