# Problem Description
This is a predator-prey positioning problem where a cat tries to catch rats on a number line. The cat has a capture radius determined by the total number of rats, and can catch any rats within that radius from its position. The goal is to calculate how many rats the cat can catch given its position and the positions of all rats.

# Visual Facts
1. The problem uses a 0-based index number line from 0 to 10
2. Two examples are shown:
   - Example 1:
     * Contains 6 rats and 1 cat
     * Cat is at position 5 (black cat silhouette)
     * Capture radius = 3 (⌊6/2⌋)
     * Shows 3 rats are captured
   
   - Example 2:
     * Contains 8 rats and 1 cat
     * Cat is at position 4
     * Capture radius = 4 (⌊8/2⌋)
     * Shows 6 rats are captured

3. Orange boxes show the capture range
4. Green boxes highlight the caught rats
5. Rats are represented by small mouse silhouettes

# Visual Patterns
1. Capture Radius Calculation:
   * Capture radius = ⌊number of rats / 2⌋
   * This is a floor division operation

2. Capture Range Rule:
   * A rat is catchable if: cat_position - radius ≤ rat_position ≤ cat_position + radius
   * The capture zone is symmetric around the cat's position

3. Counting Pattern:
   * Only rats within the capture range are counted
   * The capture range forms a continuous zone
   * Rats outside this range are not counted even if they're closer to other rats

4. Boundary Handling:
   * The capture range appears to work even if it would theoretically extend beyond the 0-10 range
   * The line appears bounded but the solution should work for any valid integer positions

5. Multiple Rats Rule:
   * Multiple rats can be caught within the same capture range
   * Each rat in range counts individually toward the total

# Solution
from typing import List

def solution(cat: int, rats: List[int]) -> int:
    """
    Given a cat's position and a list of rats positions, returns the number of rats the cat can catch.

    Parameters:
        cat (int): The position index of the cat (0-based)
        rats (List[int]): List of position indices for the rats (0-based)

    Returns:
        int: Number of rats that can be caught by the cat
    """
    cap_radius = int(len(rats) / 2)
    left_bound = cat - cap_radius
    right_bound = cat + cap_radius
    count = 0
    for i in rats:
        if i >= left_bound and i <= right_bound:
            count += 1
    return count


# Test Script

def test():
    test_cases = [
        (5,[0,1,3,6,7,10],3),
        (4,[0,1,2,6,7,8,9,10], 6),
        (7,[0,1,2,3,4,5,6,8,9,10], 8),
        (3,[0,1,2,4,5,6,7,8,9,10], 8),
        (5,[0,1,2,3,10], 1),
        (8,[0,1,2,3,4,5,6,7,10], 5),
        (4,[0,2,5,8,3], 3),
        (2,[0,1,7,8,9,10], 2),   
        (1,[0,2,3,4,5,6,7,8,9,10], 6),
        (6,[0,1,2,3,4,5,7,8,9,10], 9)
        
    ]

    for cat, rats, expected_output in test_cases:
        try:
            output = solution(cat, rats)
        except Exception as e:
            error_message = (
                f"An exception occurred while running the test case:\n"
                f"`cat`: {cat}\n"
                f"`rats`: {rats}\n\n"
                f"Exception: '{str(e)}'"
            )
            assert False, error_message

        if output != expected_output:
            error_message = (
                f"The following Test Case failed:\n"
                f"`cat`: {cat}\n"
                f"`rats`: {rats}\n\n"
                f"Actual Output: {output}\n"
                f"Expected Output: {expected_output}"
            )
            assert False, error_message

test()