Skip to content

Commit c395b3b

Browse files
Add Armstrong number algorithm in maths module
1 parent 3c88735 commit c395b3b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

maths/armstrong_number.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
def is_armstrong(number: int) -> bool:
2+
"""
3+
Check if a number is an Armstrong number.
4+
5+
>>> is_armstrong(153)
6+
True
7+
>>> is_armstrong(123)
8+
False
9+
"""
10+
digits = list(map(int, str(number)))
11+
power = len(digits)
12+
return sum(d ** power for d in digits) == number
13+
14+
15+
if __name__ == "__main__":
16+
print(is_armstrong(153))

0 commit comments

Comments
 (0)