Skip to content

Commit 69707bf

Browse files
Minimization of while loop in Armstrong Numbers (#9976)
* Minimization of while loop in Armstrong Numbers The while loop is removed and simple length calculation is used so the task of minimization of while loop is achieved * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 96f8177 commit 69707bf

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

Diff for: maths/armstrong_numbers.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ def armstrong_number(n: int) -> bool:
2929
number_of_digits = 0
3030
temp = n
3131
# Calculation of digits of the number
32-
while temp > 0:
33-
number_of_digits += 1
34-
temp //= 10
32+
number_of_digits = len(str(n))
3533
# Dividing number into separate digits and find Armstrong number
3634
temp = n
3735
while temp > 0:

0 commit comments

Comments
 (0)