You are viewing a single comment's thread from:

RE: AP Computer Science - The Armstrong Numbers

in #tutorials7 years ago (edited)

Hi, I took your great post as reason to implement this in python myself.

def getArmstongNumbers(start, end):
    armstongNumbers = []
    for nr in range(start, end):
        sum = 0
        for digit in str(nr):
            sum += pow(int(digit), len(str(nr)))
        if sum == nr:
            armstongNumbers += [nr]
    return armstongNumbers

print(getArmstongNumbers(1, 100000))

Maybe we will find more users who post their own implementation here.

Sort:  
[v for p,v in enumerate([sum([int(d)**len(str(i))for d in str(i)])for i in range(7**6)])if p==v]

The readability is lost, but it is even shorter.

Loading...

Awesome work guys! Glad I could inspire you to try it out!