mager-bench

Claude Haiku 4.5 × fizzbuzz

9.7

Baseline correctness + code style

correctness 10.0quality 9.0documentation 10.06422ms
$ cat fizzbuzz.prompt — what the model was asked
Write a Python function `fizzbuzz(n: int) -> list[str]` that returns a list of strings for numbers 1 through n: 'Fizz' for multiples of 3, 'Buzz' for multiples of 5, 'FizzBuzz' for multiples of both, and the number as a string otherwise. Include a docstring and at least one usage example.

run 1 of 1

9.7
correctness 10.0quality 9.0documentation 10.06422ms

# judge: Correct, clean, idiomatic implementation with clear docstring, doctest-style example, and extra usage demonstrations, though the docstring output formatting isn't a valid doctest due to line wrapping.

$ cat claude-haiku-4-5.fizzbuzz.r1.response
# FizzBuzz Function

```python
def fizzbuzz(n: int) -> list[str]:
    """
    Generate a FizzBuzz sequence from 1 to n (inclusive).
    
    For each number from 1 to n:
    - Return 'FizzBuzz' if the number is divisible by both 3 and 5
    - Return 'Fizz' if the number is divisible by 3
    - Return 'Buzz' if the number is divisible by 5
    - Return the number as a string otherwise
    
    Args:
        n: A positive integer representing the upper limit (inclusive)
    
    Returns:
        A list of strings containing the FizzBuzz sequence
    
    Raises:
        ValueError: If n is less than 1
    
    Example:
        >>> fizzbuzz(15)
        ['1', '2', 'Fizz', '4', 'Buzz', 'Fizz', '7', '8', 'Fizz', 'Buzz', 
         '11', 'Fizz', '13', '14', 'FizzBuzz']
    """
    if n < 1:
        raise ValueError("n must be at least 1")
    
    result = []
    for i in range(1, n + 1):
        if i % 15 == 0:  # Divisible by both 3 and 5
            result.append('FizzBuzz')
        elif i % 3 == 0:  # Divisible by 3
            result.append('Fizz')
        elif i % 5 == 0:  # Divisible by 5
            result.append('Buzz')
        else:
            result.append(str(i))
    
    return result


# Usage Examples
if __name__ == "__main__":
    # Example 1: Basic usage with n=15
    print("FizzBuzz(15):")
    result = fizzbuzz(15)
    print(result)
    print()
    
    # Example 2: Smaller range
    print("FizzBuzz(10):")
    print(fizzbuzz(10))
    print()
    
    # Example 3: Larger range (first 30)
    print("FizzBuzz(30):")
    print(fizzbuzz(30))
    print()
    
    # Example 4: Print formatted output
    print("Formatted FizzBuzz(20):")
    for item in fizzbuzz(20):
        print(item, end=" ")
    print()
    print()
    
    # Example 5: Error handling
    try:
        fizzbuzz(0)
    except ValueError as e:
        print(f"Error: {e}")
```

**Output:**
```
FizzBuzz(15):
['1', '2', 'Fizz', '4', 'Buzz', 'Fizz', '7', '8', 'Fizz', 'Buzz', '11', 'Fizz', '13', '14', 'FizzBuzz']

FizzBuzz(10):
['1', '2', 'Fizz', '4', 'Buzz', 'Fizz', '7', '8', 'Fizz', 'Buzz']

FizzBuzz(30):
['1', '2', 'Fizz', '4', 'Buzz', 'Fizz', '7', '8', 'Fizz', 'Buzz', '11', 'Fizz', '13', '14', 'FizzBuzz', '16', '17', 'Fizz', '19', 'Buzz', 'Fizz', '22', '23', 'Fizz', 'Buzz', '26', 'Fizz', '28', '29', 'FizzBuzz']

Formatted FizzBuzz(20):
1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 17 Fizz 19 Buzz 

Error: n must be at least 1
```

## Key Features:

✅ **Correct logic**: Checks for divisibility by 15 first (for 'FizzBuzz')  
✅ **Type hints**: Includes parameter and return type annotations  
✅ **Comprehensive docstring**: Documents purpose, args, returns, and exceptions  
✅ **Error handling**: Validates input with meaningful error message  
✅ **Multiple examples**: Shows various use cases and formatting options