From 0847ab3f3e0f369caffd6dc5367fe084722d1a1f Mon Sep 17 00:00:00 2001 From: vectorperfect <108605954+ambiguousphoton@users.noreply.github.com> Date: Sun, 8 Oct 2023 20:37:49 +0530 Subject: [PATCH 1/4] Update armstrong_numbers.py --- 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..07c9f95089a7 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(temp)) + 1 # Dividing number into separate digits and find Armstrong number temp = n while temp > 0: From 7a154fada442a049afa7d959982c7fc9cd4015b6 Mon Sep 17 00:00:00 2001 From: vectorperfect <108605954+ambiguousphoton@users.noreply.github.com> Date: Sun, 8 Oct 2023 20:50:44 +0530 Subject: [PATCH 2/4] Update armstrong_numbers.py --- maths/armstrong_numbers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/armstrong_numbers.py b/maths/armstrong_numbers.py index 07c9f95089a7..619096e61b0d 100644 --- a/maths/armstrong_numbers.py +++ b/maths/armstrong_numbers.py @@ -1,3 +1,4 @@ +import math """ An Armstrong number is equal to the sum of its own digits each raised to the power of the number of digits. @@ -8,7 +9,6 @@ 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) From 66c50b35ce58ebc86e7903d75dc6a7a47c06fce2 Mon Sep 17 00:00:00 2001 From: vectorperfect <108605954+ambiguousphoton@users.noreply.github.com> Date: Sun, 8 Oct 2023 20:55:47 +0530 Subject: [PATCH 3/4] Update armstrong_numbers.py --- maths/armstrong_numbers.py | 1 + 1 file changed, 1 insertion(+) diff --git a/maths/armstrong_numbers.py b/maths/armstrong_numbers.py index 619096e61b0d..257630706222 100644 --- a/maths/armstrong_numbers.py +++ b/maths/armstrong_numbers.py @@ -31,6 +31,7 @@ def armstrong_number(n: int) -> bool: temp = n # Calculation of digits of the number number_of_digits = math.floor(math.log10(temp)) + 1 + # Dividing number into separate digits and find Armstrong number temp = n while temp > 0: From 85b414907428d8aa2ddcfeadb092985108c02b1a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 8 Oct 2023 15:33:19 +0000 Subject: [PATCH 4/4] [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 257630706222..48afd8bea182 100644 --- a/maths/armstrong_numbers.py +++ b/maths/armstrong_numbers.py @@ -1,4 +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. @@ -31,7 +32,7 @@ def armstrong_number(n: int) -> bool: temp = n # Calculation of digits of the number number_of_digits = math.floor(math.log10(temp)) + 1 - + # Dividing number into separate digits and find Armstrong number temp = n while temp > 0: