Ad
Code
Diff
  • #This works for base-10 only. Other bases might require using text-type objects.
    def is_Armstrong(n):
        return n == sum(map(lambda x: int(x)**len(str(n)), str(n)))
    • #This works for base-10 only. Other bases might require using text-type objects.
    • def is_Armstrong(n):
    • m = n # Make a copy of n for use obtaining digits.
    • #Bearing in mind that n must be kept available.
    • digits = [] #Store digits here
    • #Get digits
    • while (m):
    • digits.append(m%10)
    • m //= 10
    • #Get count of digits
    • x = len(digits)
    • #Compare original value to sum of digit ^ count
    • return n == sum(d ** x for d in digits)
    • return n == sum(map(lambda x: int(x)**len(str(n)), str(n)))