Skip to content

Commit

Permalink
generalization bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
3kwa committed Jan 25, 2012
1 parent a65b266 commit 15c4996
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion 062.py
Expand Up @@ -9,21 +9,35 @@
when the length of the list of cuve for a key reaches permutation we are done!
"""

import sys
from collections import defaultdict

def find(permutation):
"""
>>> find(3)
41063625
>>> find(5)
127035954683
>>> find(6)
1000600120008
"""
seen = defaultdict(list)
i = 1
result = sys.maxint
count = sys.maxint
while True:
cube = i ** 3
key = ''.join( sorted(digit for digit in str(cube)) )
seen[key].append(cube)
if len(seen[key]) == permutation:
return min(seen[key])
# the first encounter may not yield the smallest
min_ = min(seen[key])
result = min_ if min_ < result else result
count = len(key)
# if the new key is longer than the smallest solution so far
if len(key) > count:
return result

i += 1

if __name__ == '__main__':
Expand Down

0 comments on commit 15c4996

Please sign in to comment.