Skip to content

Commit 84b59c8

Browse files
yaadhuupre-commit-ci[bot]MaximSmolskiy
authored
Handle gcd(0, 0) edge case (#14215)
* Use TypeError for non-string input in count_vowels * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix docstring and improve input validation in kth_lexicographic_permutation * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Handle gcd(0, 0) edge case * Update kth_lexicographic_permutation.py * Update count_vowels.py * Update greatest_common_divisor.py --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Maxim Smolskiy <mithridatus@mail.ru>
1 parent 81fcb90 commit 84b59c8

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

maths/greatest_common_divisor.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ def greatest_common_divisor(a: int, b: int) -> int:
3030
3
3131
>>> greatest_common_divisor(-3, -9)
3232
3
33+
>>> greatest_common_divisor(0, 0)
34+
0
3335
"""
3436
return abs(b) if a == 0 else greatest_common_divisor(b % a, a)
3537

@@ -50,6 +52,8 @@ def gcd_by_iterative(x: int, y: int) -> int:
5052
1
5153
>>> gcd_by_iterative(11, 37)
5254
1
55+
>>> gcd_by_iterative(0, 0)
56+
0
5357
"""
5458
while y: # --> when y=0 then loop will terminate and return x as final GCD.
5559
x, y = y, x % y

0 commit comments

Comments
 (0)