Skip to content

Instantly share code, notes, and snippets.

@jakedobkin
Created December 19, 2011 21:00
Show Gist options
  • Select an option

  • Save jakedobkin/1498852 to your computer and use it in GitHub Desktop.

Select an option

Save jakedobkin/1498852 to your computer and use it in GitHub Desktop.
Euler 62: Complete
# http://projecteuler.net/problem=62
def cube(n):
return n*n*n
def hash(n):
string = str(n)
numbers = []
for i in range(0,len(string)):
numbers.append(string[i:i+1])
numbers.sort(reverse=True)
string = ""
for j in range (0,len(numbers)):
string = string+str(numbers[j])
return string
# add each hash to list
hash_list = []
for k in range (0,10000):
hash_list.append(hash(cube(k)))
# check how many matches each hash has- if it has 5, print it
for j in range(0,len(hash_list)):
if hash_list.count(hash_list[j]) == 5:
print j, cube(j)
exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment