In this problem we are trying to find the smallest cubic number that can have its digits rearranged to produce four additional cubic numbers. Or in other words, we are looking for a string of digits that can be rearranged to produce five cubic numbers.
I tried doing this the dumb way, but that didn't work very well. The Python permutations function is useful for lots of things, but not in this problem.
Here is my solution.
upper_limit = 10000 #Guess at the upper limit sorted_cubics =  cubics =  print('Generating cubics...') for i in range(2,upper_limit): cubics.append(i**3) #Use this at the end to look up the answer. x = list(str(i**3)) #sorted_cubics contains each of the cubics with x = sorted(x) #their digits sorted. x = ''.join(x) sorted_cubics.append(x) print('Checking...') for i in sorted_cubics: c = sorted_cubics.count(i) #Count how many cubics have the same digits. if c == 5: #If there are 5 with the same digits... k = sorted_cubics.index(i) #Use this to look up the actual number. print('The answer is %s' %(cubics[k])) break print('Done')