← run

he-015

1.000
1/1 tests· basic
Challenge · difficulty 1/5
# HumanEval/15

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 string_sequence(n: int) -> str:
    """ Return a string containing space-delimited numbers starting from 0 upto n inclusive.
    >>> string_sequence(0)
    '0'
    >>> string_sequence(5)
    '0 1 2 3 4 5'
    """
```

<!-- imported from OpenAI HumanEval (HumanEval/15) -->
tests/test_he_015.py
# Auto-generated from OpenAI HumanEval HumanEval/15. Do not edit by hand.
from solution import *  # noqa: F401,F403 (prompt helpers may be referenced by tests)
from solution import string_sequence as candidate

METADATA = {
    'author': 'jt',
    'dataset': 'test'
}


def check(candidate):
    assert candidate(0) == '0'
    assert candidate(3) == '0 1 2 3'
    assert candidate(10) == '0 1 2 3 4 5 6 7 8 9 10'


def test_he_015():
    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 string_sequence(n: int) -> str:
    """ Return a string containing space-delimited numbers starting from 0 upto n inclusive.
    >>> string_sequence(0)
    '0'
    >>> string_sequence(5)
    '0 1 2 3 4 5'
    """
    return ' '.join(str(i) for i in range(n + 1))
```

Test output (stdout)

.                                                                        [100%]
1 passed in 0.01s
Reasoning (chain-of-thought)
The task is to implement a function `string_sequence(n: int) -> str` that returns a string containing space-delimited numbers starting from 0 up to n inclusive.

Looking at the examples:
- `string_sequence(0)` returns `'0'`
- `string_sequence(5)` returns `'0 1 2 3 4 5'`

So I need to:
1. Generate numbers from 0 to n (inclusive)
2. Convert them to strings
3. Join them with spaces

The simplest approach is to use `range(0, n+1)` to get numbers from 0 to n inclusive, convert each to string, and join with spaces.

Let me write the solution:

```python
def string_sequence(n: int) -> str:
    return ' '.join(str(i) for i in range(n + 1))
```

This should work correctly for all cases:
- n=0: range(1) gives [0], joined gives '0'
- n=5: range(6) gives [0,1,2,3,4,5], joined gives '0 1 2 3 4 5'