Skip to content

Latest commit

 

History

History
188 lines (181 loc) · 5.44 KB

File metadata and controls

188 lines (181 loc) · 5.44 KB

Results of GPT-3.5 on HumanEval/151

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

Prompt

Tokens: 163

def double_the_difference(lst):
    '''
    Given a list of numbers, return the sum of squares of the numbers
    in the list that are odd. Ignore numbers that are negative or not integers.
    
    double_the_difference([1, 3, 2, 0]) == 1 + 9 + 0 + 0 = 10
    double_the_difference([-1, -2, 0]) == 0
    double_the_difference([9, -2]) == 81
    double_the_difference([0]) == 0  
   
    If the input list is empty, return 0.
    '''

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

Correct solution

def double_the_difference(lst):
    '''
    Given a list of numbers, return the sum of squares of the numbers
    in the list that are odd. Ignore numbers that are negative or not integers.
    
    double_the_difference([1, 3, 2, 0]) == 1 + 9 + 0 + 0 = 10
    double_the_difference([-1, -2, 0]) == 0
    double_the_difference([9, -2]) == 81
    double_the_difference([0]) == 0  
   
    If the input list is empty, return 0.
    '''return sum([i**2 for i in lst if i > 0 and i%2!=0 and "." not in str(i)])

Unit tests

def check(candidate):

    # Check some simple cases
    assert candidate([]) == 0 , "This prints if this assert fails 1 (good for debugging!)"
    assert candidate([5, 4]) == 25 , "This prints if this assert fails 2 (good for debugging!)"
    assert candidate([0.1, 0.2, 0.3]) == 0 , "This prints if this assert fails 3 (good for debugging!)"
    assert candidate([-10, -20, -30]) == 0 , "This prints if this assert fails 4 (good for debugging!)"


    # Check some edge cases that are easy to work out by hand.
    assert candidate([-1, -2, 8]) == 0, "This prints if this assert fails 5 (also good for debugging!)"
    assert candidate([0.2, 3, 5]) == 34, "This prints if this assert fails 6 (also good for debugging!)"
    lst = list(range(-99, 100, 2))
    odd_sum = sum([i**2 for i in lst if i%2!=0 and i > 0])
    assert candidate(lst) == odd_sum , "This prints if this assert fails 7 (good for debugging!)"

Runs

✅ Run 1

Start time: 2023-07-18 17:03:23
Duration: 2.74s
Completion tokens: 59
Result: Pass

def double_the_difference(lst):
    sum_of_squares = 0
    for num in lst:
        if isinstance(num, int) and num >= 0 and num % 2 != 0:
            sum_of_squares += num ** 2
    return sum_of_squares

✅ Run 2

Start time: 2023-07-18 17:03:20
Duration: 2.6s
Completion tokens: 59
Result: Pass

def double_the_difference(lst):
    sum_of_squares = 0
    for num in lst:
        if isinstance(num, int) and num >= 0 and num % 2 != 0:
            sum_of_squares += num ** 2
    return sum_of_squares

✅ Run 3

Start time: 2023-07-18 17:03:18
Duration: 2.63s
Completion tokens: 59
Result: Pass

def double_the_difference(lst):
    sum_of_squares = 0
    for num in lst:
        if isinstance(num, int) and num >= 0 and num % 2 != 0:
            sum_of_squares += num ** 2
    return sum_of_squares

✅ Run 4

Start time: 2023-07-18 17:03:15
Duration: 2.58s
Completion tokens: 59
Result: Pass

def double_the_difference(lst):
    sum_of_squares = 0
    for num in lst:
        if isinstance(num, int) and num >= 0 and num % 2 != 0:
            sum_of_squares += num ** 2
    return sum_of_squares

✅ Run 5

Start time: 2023-07-18 17:02:41
Duration: 33.54s
Completion tokens: 59
Result: Pass

def double_the_difference(lst):
    sum_of_squares = 0
    for num in lst:
        if isinstance(num, int) and num >= 0 and num % 2 != 0:
            sum_of_squares += num ** 2
    return sum_of_squares

✅ Run 6

Start time: 2023-07-18 17:02:38
Duration: 3.38s
Completion tokens: 59
Result: Pass

def double_the_difference(lst):
    sum_of_squares = 0
    for num in lst:
        if isinstance(num, int) and num >= 0 and num % 2 != 0:
            sum_of_squares += num ** 2
    return sum_of_squares

✅ Run 7

Start time: 2023-07-18 17:02:35
Duration: 2.5s
Completion tokens: 59
Result: Pass

def double_the_difference(lst):
    sum_of_squares = 0
    for num in lst:
        if isinstance(num, int) and num >= 0 and num % 2 != 0:
            sum_of_squares += num ** 2
    return sum_of_squares

✅ Run 8

Start time: 2023-07-18 17:02:32
Duration: 2.8s
Completion tokens: 59
Result: Pass

def double_the_difference(lst):
    sum_of_squares = 0
    for num in lst:
        if isinstance(num, int) and num >= 0 and num % 2 != 0:
            sum_of_squares += num ** 2
    return sum_of_squares

✅ Run 9

Start time: 2023-07-18 17:02:29
Duration: 2.83s
Completion tokens: 59
Result: Pass

def double_the_difference(lst):
    sum_of_squares = 0
    for num in lst:
        if isinstance(num, int) and num >= 0 and num % 2 != 0:
            sum_of_squares += num ** 2
    return sum_of_squares

✅ Run 10

Start time: 2023-07-18 17:02:26
Duration: 3.0s
Completion tokens: 59
Result: Pass

def double_the_difference(lst):
    sum_of_squares = 0
    for num in lst:
        if isinstance(num, int) and num >= 0 and num % 2 != 0:
            sum_of_squares += num ** 2
    return sum_of_squares