Mbpp/67

❌ 均未通过 Base: FAIL Plus: FAIL
测试评估
指标结果
Base 测试FAIL
Plus 测试FAIL
代码长度1320 字符
模型生成的代码 (1320 字符)
def bell_number(n: int) -> int:
    """
    Returns the n-th Bell number, which is the number of ways to partition a set of n elements.
    Uses the Bell triangle method (also known as Aitken's array).
    """
    if n < 0:
        raise ValueError("n must be a non-negative integer")
    if n <= 1:
        return 1
    
    # Initialize the Bell triangle. We only need to keep the previous row.
    bell_prev = [1]  # row 0
    for i in range(1, n):
        bell_curr = [bell_prev[-1]]
        for j in range(1, i + 1):
            bell_curr.append(bell_curr[-1] + bell_prev[j - 1])
        bell_prev = bell_curr
    # The first element of the last row is B_{i}, but we need B_n.
    # At the end of the loop, bell_prev corresponds to row n-1.
    # We need one more iteration to get row n.
    bell_curr = [bell_prev[-1]]
    for j in range(1, n + 1):
        bell_curr.append(bell_curr[-1] + bell_prev[j - 1])
    return bell_curr[-1]  # Actually, B_n is the first element of row n, which is bell_curr[0]? Wait.
    # Let's check: In Bell triangle, first column gives Bell numbers. Row 0: [1], B0=1.
    # Row 1: start with last of prev row (1) -> [1]; then j=1: 1+prev[0]=2 -> [1,2]; first is 1 = B1.
    # Row 2: start with 2 -> [2]; j=1: 2+prev[0]=2+1=3 -> [2,3]; j=2: 3+prev[1]=3+2=5 -> [2,3,5]; first is 2 = B2.
Base 失败测试用例
  • [2]
Plus 失败测试用例
  • [100]