RE: AP Computer Science - The Armstrong Numbers

You are viewing a single comment's thread from:

AP Computer Science - The Armstrong Numbers

in tutorials •  7 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.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  
[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!