Skip to content

Removed while loop to get no_of_digits in Armstrong Numbers #10127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions maths/armstrong_numbers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import math

"""
An Armstrong number is equal to the sum of its own digits each raised to the
power of the number of digits.
Expand Down Expand Up @@ -29,9 +31,8 @@ def armstrong_number(n: int) -> bool:
number_of_digits = 0
temp = n
# Calculation of digits of the number
while temp > 0:
number_of_digits += 1
temp //= 10
number_of_digits = math.floor(math.log10(temp)) + 1

# Dividing number into separate digits and find Armstrong number
temp = n
while temp > 0:
Expand Down