From 485cc48347664108dfb167272c4e638a3295c3b8 Mon Sep 17 00:00:00 2001 From: "nihal.r" Date: Sat, 7 Oct 2023 11:38:09 +0530 Subject: [PATCH 1/2] enhanced code in srmstring_number --- maths/armstrong_numbers.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/maths/armstrong_numbers.py b/maths/armstrong_numbers.py index 26709b428b78..ff31b1a7e6ee 100644 --- a/maths/armstrong_numbers.py +++ b/maths/armstrong_numbers.py @@ -8,6 +8,7 @@ On-Line Encyclopedia of Integer Sequences entry: https://oeis.org/A005188 """ +import math PASSING = (1, 153, 370, 371, 1634, 24678051, 115132219018763992565095597973971522401) FAILING: tuple = (-153, -1, 0, 1.2, 200, "A", [], {}, None) @@ -29,9 +30,7 @@ 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(n)+1) # Dividing number into separate digits and find Armstrong number temp = n while temp > 0: From 97bcf89d34821605ae57b6a85f97a8df8ad1b89e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 7 Oct 2023 06:12:43 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/armstrong_numbers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/maths/armstrong_numbers.py b/maths/armstrong_numbers.py index ff31b1a7e6ee..a3029a2ee1d9 100644 --- a/maths/armstrong_numbers.py +++ b/maths/armstrong_numbers.py @@ -9,6 +9,7 @@ On-Line Encyclopedia of Integer Sequences entry: https://oeis.org/A005188 """ import math + PASSING = (1, 153, 370, 371, 1634, 24678051, 115132219018763992565095597973971522401) FAILING: tuple = (-153, -1, 0, 1.2, 200, "A", [], {}, None) @@ -30,7 +31,7 @@ def armstrong_number(n: int) -> bool: number_of_digits = 0 temp = n # Calculation of digits of the number - number_of_digits = math.floor(math.log10(n)+1) + number_of_digits = math.floor(math.log10(n) + 1) # Dividing number into separate digits and find Armstrong number temp = n while temp > 0: