Skip to content

Latest commit

 

History

History
275 lines (261 loc) · 8.05 KB

File metadata and controls

275 lines (261 loc) · 8.05 KB

Results of GPT-3.5 on HumanEval/88

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

Prompt

Tokens: 229

def sort_array(array):
    """
    Given an array of non-negative integers, return a copy of the given array after sorting,
    you will sort the given array in ascending order if the sum( first index value, last index value) is odd,
    or sort it in descending order if the sum( first index value, last index value) is even.

    Note:
    * don't change the given array.

    Examples:
    * sort_array([]) => []
    * sort_array([5]) => [5]
    * sort_array([2, 4, 3, 0, 1, 5]) => [0, 1, 2, 3, 4, 5]
    * sort_array([2, 4, 3, 0, 1, 5, 6]) => [6, 5, 4, 3, 2, 1, 0]
    """

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

Correct solution

def sort_array(array):
    """
    Given an array of non-negative integers, return a copy of the given array after sorting,
    you will sort the given array in ascending order if the sum( first index value, last index value) is odd,
    or sort it in descending order if the sum( first index value, last index value) is even.

    Note:
    * don't change the given array.

    Examples:
    * sort_array([]) => []
    * sort_array([5]) => [5]
    * sort_array([2, 4, 3, 0, 1, 5]) => [0, 1, 2, 3, 4, 5]
    * sort_array([2, 4, 3, 0, 1, 5, 6]) => [6, 5, 4, 3, 2, 1, 0]
    """return [] if len(array) == 0 else sorted(array, reverse= (array[0]+array[-1]) % 2 == 0)

Unit tests

def check(candidate):

    # Check some simple cases
    assert True, "This prints if this assert fails 1 (good for debugging!)"
    assert candidate([]) == [], "Error"
    assert candidate([5]) == [5], "Error"
    assert candidate([2, 4, 3, 0, 1, 5]) == [0, 1, 2, 3, 4, 5], "Error"
    assert candidate([2, 4, 3, 0, 1, 5, 6]) == [6, 5, 4, 3, 2, 1, 0], "Error"

    # Check some edge cases that are easy to work out by hand.
    assert True, "This prints if this assert fails 2 (also good for debugging!)"
    assert candidate([2, 1]) == [1, 2], "Error"
    assert candidate([15, 42, 87, 32 ,11, 0]) == [0, 11, 15, 32, 42, 87], "Error"
    assert candidate([21, 14, 23, 11]) == [23, 21, 14, 11], "Error"

Runs

✅ Run 1

Start time: 2023-07-18 17:14:34
Duration: 7.89s
Completion tokens: 254
Result: Pass

def sort_array(array):
    """
    Given an array of non-negative integers, return a copy of the given array after sorting,
    you will sort the given array in ascending order if the sum( first index value, last index value) is odd,
    or sort it in descending order if the sum( first index value, last index value) is even.

    Note:
    * don't change the given array.

    Examples:
    * sort_array([]) => []
    * sort_array([5]) => [5]
    * sort_array([2, 4, 3, 0, 1, 5]) => [0, 1, 2, 3, 4, 5]
    * sort_array([2, 4, 3, 0, 1, 5, 6]) => [6, 5, 4, 3, 2, 1, 0]
    """
    sorted_array = array.copy()
    if len(sorted_array) > 0:
        if (sorted_array[0] + sorted_array[-1]) % 2 == 0:
            sorted_array.sort(reverse=True)
        else:
            sorted_array.sort()
    return sorted_array

✅ Run 2

Start time: 2023-07-18 17:14:31
Duration: 3.4s
Completion tokens: 85
Result: Pass

def sort_array(array):
    sorted_array = array.copy()
    if len(sorted_array) == 0:
        return sorted_array
    elif len(sorted_array) == 1:
        return sorted_array
    else:
        if (sorted_array[0] + sorted_array[-1]) % 2 == 0:
            sorted_array.sort(reverse=True)
        else:
            sorted_array.sort()
        return sorted_array

✅ Run 3

Start time: 2023-07-18 17:14:21
Duration: 9.47s
Completion tokens: 259
Result: Pass

def sort_array(array):
    """
    Given an array of non-negative integers, return a copy of the given array after sorting,
    you will sort the given array in ascending order if the sum( first index value, last index value) is odd,
    or sort it in descending order if the sum( first index value, last index value) is even.

    Note:
    * don't change the given array.

    Examples:
    * sort_array([]) => []
    * sort_array([5]) => [5]
    * sort_array([2, 4, 3, 0, 1, 5]) => [0, 1, 2, 3, 4, 5]
    * sort_array([2, 4, 3, 0, 1, 5, 6]) => [6, 5, 4, 3, 2, 1, 0]
    """
    sorted_array = array.copy()
    if len(sorted_array) < 2:
        return sorted_array
    if (sorted_array[0] + sorted_array[-1]) % 2 == 0:
        sorted_array.sort(reverse=True)
    else:
        sorted_array.sort()
    return sorted_array

✅ Run 4

Start time: 2023-07-18 17:14:18
Duration: 3.37s
Completion tokens: 85
Result: Pass

def sort_array(array):
    sorted_array = array.copy()
    if len(sorted_array) == 0:
        return sorted_array
    elif len(sorted_array) == 1:
        return sorted_array
    else:
        if (sorted_array[0] + sorted_array[-1]) % 2 == 0:
            sorted_array.sort(reverse=True)
        else:
            sorted_array.sort()
        return sorted_array

✅ Run 5

Start time: 2023-07-18 17:14:15
Duration: 2.91s
Completion tokens: 72
Result: Pass

def sort_array(array):
    sorted_array = array.copy()
    if len(sorted_array) == 0:
        return sorted_array
    if (sorted_array[0] + sorted_array[-1]) % 2 == 0:
        sorted_array.sort(reverse=True)
    else:
        sorted_array.sort()
    return sorted_array

✅ Run 6

Start time: 2023-07-18 17:14:12
Duration: 3.01s
Completion tokens: 72
Result: Pass

def sort_array(array):
    sorted_array = array.copy()
    if len(sorted_array) == 0:
        return sorted_array
    if (sorted_array[0] + sorted_array[-1]) % 2 == 0:
        sorted_array.sort(reverse=True)
    else:
        sorted_array.sort()
    return sorted_array

❌ Run 7

Start time: 2023-07-18 17:14:03
Duration: 8.85s
Completion tokens: 237
Result: Fail

def sort_array(array):
    """
    Given an array of non-negative integers, return a copy of the given array after sorting,
    you will sort the given array in ascending order if the sum( first index value, last index value) is odd,
    or sort it in descending order if the sum( first index value, last index value) is even.

    Note:
    * don't change the given array.

    Examples:
    * sort_array([]) => []
    * sort_array([5]) => [5]
    * sort_array([2, 4, 3, 0, 1, 5]) => [0, 1, 2, 3, 4, 5]
    * sort_array([2, 4, 3, 0, 1, 5, 6]) => [6, 5, 4, 3, 2, 1, 0]
    """
    sorted_array = sorted(array)
    if (array[0] + array[-1]) % 2 == 0:
        return sorted_array[::-1]
    else:
        return sorted_array

✅ Run 8

Start time: 2023-07-18 17:13:59
Duration: 3.44s
Completion tokens: 85
Result: Pass

def sort_array(array):
    sorted_array = array.copy()
    if len(sorted_array) == 0:
        return sorted_array
    elif len(sorted_array) == 1:
        return sorted_array
    else:
        if (sorted_array[0] + sorted_array[-1]) % 2 == 0:
            sorted_array.sort(reverse=True)
        else:
            sorted_array.sort()
        return sorted_array

✅ Run 9

Start time: 2023-07-18 17:13:56
Duration: 3.04s
Completion tokens: 73
Result: Pass

def sort_array(array):
    sorted_array = array.copy()
    if len(sorted_array) == 0:
        return sorted_array
    
    if (sorted_array[0] + sorted_array[-1]) % 2 == 0:
        sorted_array.sort(reverse=True)
    else:
        sorted_array.sort()
    
    return sorted_array

✅ Run 10

Start time: 2023-07-18 17:13:52
Duration: 3.6s
Completion tokens: 85
Result: Pass

def sort_array(array):
    sorted_array = array.copy()
    if len(sorted_array) == 0:
        return sorted_array
    elif len(sorted_array) == 1:
        return sorted_array
    else:
        if (sorted_array[0] + sorted_array[-1]) % 2 == 0:
            sorted_array.sort(reverse=True)
        else:
            sorted_array.sort()
        return sorted_array