Created
December 19, 2011 21:00
-
-
Save jakedobkin/1498852 to your computer and use it in GitHub Desktop.
Euler 62: Complete
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
| # 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