Skip to content

Instantly share code, notes, and snippets.

@julio73
Last active August 29, 2015 14:07
Show Gist options
  • Save julio73/224fbe7da37b52e16d63 to your computer and use it in GitHub Desktop.
Save julio73/224fbe7da37b52e16d63 to your computer and use it in GitHub Desktop.
"""
An Armstrong number is an n-digit number that is equal to the sum of the nth powers of its digits
"""
def isArmstrongNumber(x):
return sum([n**len(str(x)) for n in [int(d) for d in list(str(x))]]) == x
[x for x in range(100000) if isArmstrongNumber(x)]
#=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407, 1634, 8208, 9474, 54748, 92727, 93084]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment