Skip to content

Latest commit

 

History

History
196 lines (184 loc) · 4.66 KB

File metadata and controls

196 lines (184 loc) · 4.66 KB

Results of GPT-3.5 on HumanEval/72

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

Prompt

Tokens: 256

def will_it_fly(q,w):
    '''
    Write a function that returns True if the object q will fly, and False otherwise.
    The object q will fly if it's balanced (it is a palindromic list) and the sum of its elements is less than or equal the maximum possible weight w.

    Example:
    will_it_fly([1, 2], 5) ➞ False 
    # 1+2 is less than the maximum possible weight, but it's unbalanced.

    will_it_fly([3, 2, 3], 1) ➞ False
    # it's balanced, but 3+2+3 is more than the maximum possible weight.

    will_it_fly([3, 2, 3], 9) ➞ True
    # 3+2+3 is less than the maximum possible weight, and it's balanced.

    will_it_fly([3], 5) ➞ True
    # 3 is less than the maximum possible weight, and it's balanced.
    '''

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

Correct solution

def will_it_fly(q,w):
    '''
    Write a function that returns True if the object q will fly, and False otherwise.
    The object q will fly if it's balanced (it is a palindromic list) and the sum of its elements is less than or equal the maximum possible weight w.

    Example:
    will_it_fly([1, 2], 5) ➞ False 
    # 1+2 is less than the maximum possible weight, but it's unbalanced.

    will_it_fly([3, 2, 3], 1) ➞ False
    # it's balanced, but 3+2+3 is more than the maximum possible weight.

    will_it_fly([3, 2, 3], 9) ➞ True
    # 3+2+3 is less than the maximum possible weight, and it's balanced.

    will_it_fly([3], 5) ➞ True
    # 3 is less than the maximum possible weight, and it's balanced.
    '''if sum(q) > w:
        return False

    i, j = 0, len(q)-1
    while i<j:
        if q[i] != q[j]:
            return False
        i+=1
        j-=1
    return True

Unit tests

def check(candidate):

    # Check some simple cases
    assert candidate([3, 2, 3], 9) is True
    assert candidate([1, 2], 5) is False
    assert candidate([3], 5) is True
    assert candidate([3, 2, 3], 1) is False


    # Check some edge cases that are easy to work out by hand.
    assert candidate([1, 2, 3], 6) is False
    assert candidate([5], 5) is True

Runs

✅ Run 1

Start time: 2023-07-18 17:16:42
Duration: 1.64s
Completion tokens: 33
Result: Pass

def will_it_fly(q,w):
    if q == q[::-1] and sum(q) <= w:
        return True
    else:
        return False

✅ Run 2

Start time: 2023-07-18 17:16:40
Duration: 2.02s
Completion tokens: 33
Result: Pass

def will_it_fly(q,w):
    if q == q[::-1] and sum(q) <= w:
        return True
    else:
        return False

✅ Run 3

Start time: 2023-07-18 17:16:39
Duration: 1.69s
Completion tokens: 33
Result: Pass

def will_it_fly(q,w):
    if q == q[::-1] and sum(q) <= w:
        return True
    else:
        return False

✅ Run 4

Start time: 2023-07-18 17:16:36
Duration: 2.28s
Completion tokens: 33
Result: Pass

def will_it_fly(q,w):
    if q == q[::-1] and sum(q) <= w:
        return True
    else:
        return False

✅ Run 5

Start time: 2023-07-18 17:16:34
Duration: 1.91s
Completion tokens: 33
Result: Pass

def will_it_fly(q,w):
    if q == q[::-1] and sum(q) <= w:
        return True
    else:
        return False

✅ Run 6

Start time: 2023-07-18 17:16:32
Duration: 1.87s
Completion tokens: 37
Result: Pass

def will_it_fly(q,w):
    if q == q[::-1] and sum(q) <= w:
        return True
    else:
        return False

✅ Run 7

Start time: 2023-07-18 17:16:30
Duration: 1.91s
Completion tokens: 34
Result: Pass

def will_it_fly(q, w):
    if q == q[::-1] and sum(q) <= w:
        return True
    else:
        return False

✅ Run 8

Start time: 2023-07-18 17:16:28
Duration: 2.19s
Completion tokens: 34
Result: Pass

def will_it_fly(q, w):
    if q == q[::-1] and sum(q) <= w:
        return True
    else:
        return False

✅ Run 9

Start time: 2023-07-18 17:16:27
Duration: 1.47s
Completion tokens: 33
Result: Pass

def will_it_fly(q,w):
    if q == q[::-1] and sum(q) <= w:
        return True
    else:
        return False

✅ Run 10

Start time: 2023-07-18 17:16:24
Duration: 2.5s
Completion tokens: 33
Result: Pass

def will_it_fly(q,w):
    if q == q[::-1] and sum(q) <= w:
        return True
    else:
        return False