he-024
1.000
Challenge · difficulty 1/5
# HumanEval/24
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 largest_divisor(n: int) -> int:
""" For a given number n, find the largest number that divides n evenly, smaller than n
>>> largest_divisor(15)
5
"""
```
<!-- imported from OpenAI HumanEval (HumanEval/24) -->
tests/test_he_024.py
# Auto-generated from OpenAI HumanEval HumanEval/24. Do not edit by hand.
from solution import * # noqa: F401,F403 (prompt helpers may be referenced by tests)
from solution import largest_divisor as candidate
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(3) == 1
assert candidate(7) == 1
assert candidate(10) == 5
assert candidate(100) == 50
assert candidate(49) == 7
def test_he_024():
check(candidate)
System prompt
You are an expert programmer. Solve the task exactly as specified. Output your solution as fenced code blocks using the required file name(s) and the exact function/type signatures requested. Prefer correctness; do not include prose outside code unless asked.
Proposed solution
```python
def largest_divisor(n: int) -> int:
""" For a given number n, find the largest number that divides n evenly, smaller than n
>>> largest_divisor(15)
5
"""
for i in range(n - 1, 0, -1):
if n % i == 0:
return i
return 1
```Test output (stdout)
. [100%] 1 passed in 0.01s