Commit Graph

4 Commits

Author SHA1 Message Date
Christian Clauss
d23e709aea
maths/sum_of_digits.py: Streamline benchmarks (#7914)
* maths/sum_of_digits.py: Streamline benchmarks

```
sum_of_digits(262144): 19 -- 0.3128329170285724 seconds
sum_of_digits_recursion(262144): 19 -- 0.34008108399575576 seconds
sum_of_digits_compact(262144): 19 -- 0.6086010000435635 seconds

sum_of_digits(1125899906842624): 76 -- 0.8079068749793805 seconds
sum_of_digits_recursion(1125899906842624): 76 -- 0.8435653329943307 seconds
sum_of_digits_compact(1125899906842624): 76 -- 1.247976207989268 seconds

sum_of_digits(1267650600228229401496703205376): 115 -- 1.6441589999594726 seconds
sum_of_digits_recursion(1267650600228229401496703205376): 115 -- 1.713684624992311 seconds
sum_of_digits_compact(1267650600228229401496703205376): 115 -- 2.2197747920290567 seconds
```

* updating DIRECTORY.md

* Update sum_of_digits.py

* Update sum_of_digits.py

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2022-11-01 14:07:11 +01:00
Lukas Esc
cafbbab125
shortened code using abs() and inplace ops (#7191)
n = -n if n < 0 else n --> n = abs(n)
n = n // 10 --> n //= 10
2022-10-30 11:56:54 +01:00
Du Yuanchao
34294b5641
Update sum_of_digits.py (#2319)
* * support negative number
* add different version

* fixup! Format Python code with psf/black push

* sum(int(c) for c in str(abs(n)))

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2020-08-16 20:31:06 +02:00
Vignesh
0904610a76
create sum_of_digits.py (#2065)
* create sum_of_digits.py

create sum_of_digits.py to find the sum of digits of a number
digit_sum(12345) ---> 15
digit_sum(12345) ---> 10

* Update sum_of_digits.py

* Update maths/sum_of_digits.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update maths/sum_of_digits.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update sum_of_digits.py

Co-authored-by: Christian Clauss <cclauss@me.com>
2020-06-02 23:38:32 +02:00