Skip to content

Commit 4226641

Browse files
authored
fix sum_of_digits.py
1 parent bf11752 commit 4226641

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

maths/sum_of_digits.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from collections.abc import Callable
2+
from timeit import timeit
3+
14
def sum_of_digits(n: int) -> int:
25
"""
36
Find the sum of digits of a number.
@@ -31,7 +34,7 @@ def sum_of_digits_recursion(n: int) -> int:
3134
0
3235
"""
3336
n = abs(n)
34-
return n if n < 10 else n % 10 + sum_of_digits(n // 10)
37+
return n if n < 10 else n % 10 + sum_of_digits_recursion(n // 10)
3538

3639

3740
def sum_of_digits_compact(n: int) -> int:
@@ -53,9 +56,6 @@ def benchmark() -> None:
5356
"""
5457
Benchmark multiple functions, with three different length int values.
5558
"""
56-
from collections.abc import Callable
57-
from timeit import timeit
58-
5959
def benchmark_a_function(func: Callable, value: int) -> None:
6060
call = f"{func.__name__}({value})"
6161
timing = timeit(f"__main__.{call}", setup="import __main__")

0 commit comments

Comments
 (0)