Skip to content

Instantly share code, notes, and snippets.

@MikaelCarpenter
Created November 17, 2016 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MikaelCarpenter/76740011255d6583a04aa6e80b6162d8 to your computer and use it in GitHub Desktop.
Save MikaelCarpenter/76740011255d6583a04aa6e80b6162d8 to your computer and use it in GitHub Desktop.
Find the max length of a narcissistic number
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