Last active
December 16, 2015 03:27
-
-
Save Radcliffe/2128ef28aa9ea0883f8a to your computer and use it in GitHub Desktop.
Powers of 3 having the same digits
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
| """ | |
| James Tanton @jamestanton asked: | |
| Is there a power of three whose digits can be rearranged to form | |
| another power of three? | |
| (https://twitter.com/jamestanton/status/676773021223272448) | |
| The following Python script searches for examples. There is no power | |
| of three, less than 3^200000, whose digits can be rearranged to form | |
| another power of three. | |
| """ | |
| from itertools import count | |
| def digits(n): | |
| return sorted(str(n)) | |
| power_of_3 = 1 | |
| digits1 = digits2 = None | |
| digits3 = digits(power_of_3) | |
| for n in count(1): | |
| power_of_3 *= 3 | |
| digits1 = digits2 | |
| digits2 = digits3 | |
| digits3 = digits(power_of_3) | |
| if digits1 == digits3: | |
| print n-2, n | |
| break | |
| if digits2 == digits3: | |
| print n-1, n | |
| break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment