he-013
1.000
Challenge · difficulty 1/5
# HumanEval/13
Implement a file **`solution.py`** that completes the function below. Keep the given name and signature; your file must define it at module level.
```python
def greatest_common_divisor(a: int, b: int) -> int:
""" Return a greatest common divisor of two integers a and b
>>> greatest_common_divisor(3, 5)
1
>>> greatest_common_divisor(25, 15)
5
"""
```
<!-- imported from OpenAI HumanEval (HumanEval/13) -->
tests/test_he_013.py
# Auto-generated from OpenAI HumanEval HumanEval/13. Do not edit by hand.
from solution import * # noqa: F401,F403 (prompt helpers may be referenced by tests)
from solution import greatest_common_divisor as candidate
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(3, 7) == 1
assert candidate(10, 15) == 5
assert candidate(49, 14) == 7
assert candidate(144, 60) == 12
def test_he_013():
check(candidate)
Proposed solution
```python
def greatest_common_divisor(a: int, b: int) -> int:
""" Return a greatest common divisor of two integers a and b
>>> greatest_common_divisor(3, 5)
1
>>> greatest_common_divisor(25, 15)
5
"""
a, b = abs(a), abs(b)
while b:
a, b = b, a % b
return a
```Test output (stdout)
. [100%]
1 passed in 0.01s