Skip to content

Latest commit

 

History

History
336 lines (333 loc) · 8.73 KB

File metadata and controls

336 lines (333 loc) · 8.73 KB

Results of GPT-3.5 on HumanEval/130

Date: 18 July, 2023
Model: gpt-3.5-turbo
Temperature: 0.2
Passing runs: 0
Total runs: 10
Success rate: 0%

Prompt

Tokens: 261

def tri(n):
    """Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in 
    the last couple centuries. However, what people don't know is Tribonacci sequence.
    Tribonacci sequence is defined by the recurrence:
    tri(1) = 3
    tri(n) = 1 + n / 2, if n is even.
    tri(n) =  tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.
    For example:
    tri(2) = 1 + (2 / 2) = 2
    tri(4) = 3
    tri(3) = tri(2) + tri(1) + tri(4)
           = 2 + 3 + 3 = 8 
    You are given a non-negative integer number n, you have to a return a list of the 
    first n + 1 numbers of the Tribonacci sequence.
    Examples:
    tri(3) = [1, 3, 2, 8]
    """

The above is an incomplete Python code fragment. Return the complete and correct code with no additional text.

Correct solution

def tri(n):
    """Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in 
    the last couple centuries. However, what people don't know is Tribonacci sequence.
    Tribonacci sequence is defined by the recurrence:
    tri(1) = 3
    tri(n) = 1 + n / 2, if n is even.
    tri(n) =  tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd.
    For example:
    tri(2) = 1 + (2 / 2) = 2
    tri(4) = 3
    tri(3) = tri(2) + tri(1) + tri(4)
           = 2 + 3 + 3 = 8 
    You are given a non-negative integer number n, you have to a return a list of the 
    first n + 1 numbers of the Tribonacci sequence.
    Examples:
    tri(3) = [1, 3, 2, 8]
    """if n == 0:
        return [1]
    my_tri = [1, 3]
    for i in range(2, n + 1):
        if i % 2 == 0:
            my_tri.append(i / 2 + 1)
        else:
            my_tri.append(my_tri[i - 1] + my_tri[i - 2] + (i + 3) / 2)
    return my_tri

Unit tests

def check(candidate):

    # Check some simple cases
    
    assert candidate(3) == [1, 3, 2.0, 8.0]
    assert candidate(4) == [1, 3, 2.0, 8.0, 3.0]
    assert candidate(5) == [1, 3, 2.0, 8.0, 3.0, 15.0]
    assert candidate(6) == [1, 3, 2.0, 8.0, 3.0, 15.0, 4.0]
    assert candidate(7) == [1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0]
    assert candidate(8) == [1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0, 5.0]
    assert candidate(9) == [1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0, 5.0, 35.0]
    assert candidate(20) == [1, 3, 2.0, 8.0, 3.0, 15.0, 4.0, 24.0, 5.0, 35.0, 6.0, 48.0, 7.0, 63.0, 8.0, 80.0, 9.0, 99.0, 10.0, 120.0, 11.0]

    # Check some edge cases that are easy to work out by hand.
    assert candidate(0) == [1]
    assert candidate(1) == [1, 3]

Runs

❌ Run 1

Start time: 2023-07-18 17:06:35
Duration: 5.36s
Completion tokens: 135
Result: Fail

def tri(n):
    sequence = [3]
    if n == 0:
        return sequence
    elif n == 1:
        sequence.append(1)
        return sequence
    elif n == 2:
        sequence.append(1)
        sequence.append(2)
        return sequence
    else:
        sequence.append(1)
        sequence.append(2)
        for i in range(3, n+1):
            if i % 2 == 0:
                sequence.append(1 + i // 2)
            else:
                sequence.append(sequence[i-1] + sequence[i-2] + sequence[i+1])
        return sequence

❌ Run 2

Start time: 2023-07-18 17:06:30
Duration: 5.18s
Completion tokens: 135
Result: Fail

def tri(n):
    sequence = [3]
    if n == 0:
        return sequence
    elif n == 1:
        sequence.append(1)
        return sequence
    elif n == 2:
        sequence.append(1)
        sequence.append(2)
        return sequence
    else:
        sequence.append(1)
        sequence.append(2)
        for i in range(3, n+1):
            if i % 2 == 0:
                sequence.append(1 + i // 2)
            else:
                sequence.append(sequence[i-1] + sequence[i-2] + sequence[i+1])
        return sequence

❌ Run 3

Start time: 2023-07-18 17:06:24
Duration: 5.38s
Completion tokens: 135
Result: Fail

def tri(n):
    sequence = [3]
    if n == 0:
        return sequence
    elif n == 1:
        sequence.append(1)
        return sequence
    elif n == 2:
        sequence.append(1)
        sequence.append(2)
        return sequence
    else:
        sequence.append(1)
        sequence.append(2)
        for i in range(3, n+1):
            if i % 2 == 0:
                sequence.append(1 + i // 2)
            else:
                sequence.append(sequence[i-1] + sequence[i-2] + sequence[i+1])
        return sequence

❌ Run 4

Start time: 2023-07-18 17:06:19
Duration: 5.48s
Completion tokens: 135
Result: Fail

def tri(n):
    sequence = [3]
    if n == 0:
        return sequence
    elif n == 1:
        sequence.append(1)
        return sequence
    elif n == 2:
        sequence.append(1)
        sequence.append(2)
        return sequence
    else:
        sequence.append(1)
        sequence.append(2)
        for i in range(3, n+1):
            if i % 2 == 0:
                sequence.append(1 + i // 2)
            else:
                sequence.append(sequence[i-1] + sequence[i-2] + sequence[i+1])
        return sequence

❌ Run 5

Start time: 2023-07-18 17:06:15
Duration: 4.06s
Completion tokens: 135
Result: Fail

def tri(n):
    sequence = [3]
    if n == 0:
        return sequence
    elif n == 1:
        sequence.append(1)
        return sequence
    elif n == 2:
        sequence.append(1)
        sequence.append(2)
        return sequence
    else:
        sequence.append(1)
        sequence.append(2)
        for i in range(3, n+1):
            if i % 2 == 0:
                sequence.append(1 + i // 2)
            else:
                sequence.append(sequence[i-1] + sequence[i-2] + sequence[i+1])
        return sequence

❌ Run 6

Start time: 2023-07-18 17:06:09
Duration: 5.38s
Completion tokens: 135
Result: Fail

def tri(n):
    sequence = [3]
    if n == 0:
        return sequence
    elif n == 1:
        sequence.append(1)
        return sequence
    elif n == 2:
        sequence.append(1)
        sequence.append(2)
        return sequence
    else:
        sequence.append(1)
        sequence.append(2)
        for i in range(3, n+1):
            if i % 2 == 0:
                sequence.append(1 + i // 2)
            else:
                sequence.append(sequence[i-1] + sequence[i-2] + sequence[i+1])
        return sequence

❌ Run 7

Start time: 2023-07-18 17:06:04
Duration: 4.92s
Completion tokens: 118
Result: Fail

def tri(n):
    sequence = [3]
    if n == 0:
        return sequence
    sequence.append(1)
    if n == 1:
        return sequence
    sequence.append(2)
    if n == 2:
        return sequence
    for i in range(3, n + 1):
        if i % 2 == 0:
            sequence.append(1 + i // 2)
        else:
            sequence.append(sequence[i - 1] + sequence[i - 2] + sequence[i + 1])
    return sequence

❌ Run 8

Start time: 2023-07-18 17:05:59
Duration: 5.19s
Completion tokens: 135
Result: Fail

def tri(n):
    sequence = [3]
    if n == 0:
        return sequence
    elif n == 1:
        sequence.append(1)
        return sequence
    elif n == 2:
        sequence.append(1)
        sequence.append(2)
        return sequence
    else:
        sequence.append(1)
        sequence.append(2)
        for i in range(3, n+1):
            if i % 2 == 0:
                sequence.append(1 + i // 2)
            else:
                sequence.append(sequence[i-1] + sequence[i-2] + sequence[i+1])
        return sequence

❌ Run 9

Start time: 2023-07-18 17:05:55
Duration: 4.12s
Completion tokens: 106
Result: Fail

def tri(n):
    sequence = [3]
    if n == 0:
        return sequence
    sequence.append(1 + n / 2)
    if n == 1:
        return sequence
    for i in range(2, n + 1):
        if i % 2 == 0:
            sequence.append(1 + i / 2)
        else:
            sequence.append(sequence[i - 1] + sequence[i - 2] + sequence[i + 1])
    return sequence

❌ Run 10

Start time: 2023-07-18 17:05:49
Duration: 5.25s
Completion tokens: 135
Result: Fail

def tri(n):
    sequence = [3]
    if n == 0:
        return sequence
    elif n == 1:
        sequence.append(1)
        return sequence
    elif n == 2:
        sequence.append(1)
        sequence.append(2)
        return sequence
    else:
        sequence.append(1)
        sequence.append(2)
        for i in range(3, n+1):
            if i % 2 == 0:
                sequence.append(1 + i // 2)
            else:
                sequence.append(sequence[i-1] + sequence[i-2] + sequence[i+1])
        return sequence