Created
November 17, 2016 22:50
-
-
Save MikaelCarpenter/76740011255d6583a04aa6e80b6162d8 to your computer and use it in GitHub Desktop.
Find the max length of a narcissistic number
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
found = False | |
i = 1 | |
# the first n digit number is 10**(n-1). | |
# the largest possible number you can get by summing n digits to the nth power is n*9**n. | |
# if that largest number is smaller than the first number of length n then no more Narcissistic numbers exist. | |
while not found: | |
if i*9**i > 10**(i-1): | |
i += 1 | |
else: | |
found = True | |
print("Max number of digits: {}".format(i - 1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment