File tree Expand file tree Collapse file tree 1 file changed +4
-4
lines changed
Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change 1+ from collections .abc import Callable
2+ from timeit import timeit
3+
14def 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
3740def 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__" )
You can’t perform that action at this time.
0 commit comments