Skip to content

Instantly share code, notes, and snippets.

@Radcliffe
Last active December 16, 2015 03:27
Show Gist options
  • Select an option

  • Save Radcliffe/2128ef28aa9ea0883f8a to your computer and use it in GitHub Desktop.

Select an option

Save Radcliffe/2128ef28aa9ea0883f8a to your computer and use it in GitHub Desktop.
Powers of 3 having the same digits
"""
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