Skip to content

Latest commit

 

History

History
240 lines (203 loc) · 5.72 KB

File metadata and controls

240 lines (203 loc) · 5.72 KB

Results of Code LLama 34B on HumanEval/120

Date: 01 September, 2023
Model: codellama-34b-instruct
Temperature: 0.2
Passing runs: 0
Total runs: 10
Success rate: 0%

Prompt

def maximum(arr, k):
    """
    Given an array arr of integers and a positive integer k, return a sorted list 
    of length k with the maximum k numbers in arr.

    Example 1:

        Input: arr = [-3, -4, 5], k = 3
        Output: [-4, -3, 5]

    Example 2:

        Input: arr = [4, -4, 4], k = 2
        Output: [4, 4]

    Example 3:

        Input: arr = [-3, 2, 1, 2, -1, -2, 1], k = 1
        Output: [2]

    Note:
        1. The length of the array will be in the range of [1, 1000].
        2. The elements in the array will be in the range of [-1000, 1000].
        3. 0 <= k <= len(arr)
    """

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

Correct solution

def maximum(arr, k):
    """
    Given an array arr of integers and a positive integer k, return a sorted list 
    of length k with the maximum k numbers in arr.

    Example 1:

        Input: arr = [-3, -4, 5], k = 3
        Output: [-4, -3, 5]

    Example 2:

        Input: arr = [4, -4, 4], k = 2
        Output: [4, 4]

    Example 3:

        Input: arr = [-3, 2, 1, 2, -1, -2, 1], k = 1
        Output: [2]

    Note:
        1. The length of the array will be in the range of [1, 1000].
        2. The elements in the array will be in the range of [-1000, 1000].
        3. 0 <= k <= len(arr)
    """if k == 0:
        return []
    arr.sort()
    ans = arr[-k:]
    return ans

Unit tests

def check(candidate):

    # Check some simple cases
    assert candidate([-3, -4, 5], 3) == [-4, -3, 5]
    assert candidate([4, -4, 4], 2) == [4, 4]
    assert candidate([-3, 2, 1, 2, -1, -2, 1], 1) == [2]
    assert candidate([123, -123, 20, 0 , 1, 2, -3], 3) == [2, 20, 123]
    assert candidate([-123, 20, 0 , 1, 2, -3], 4) == [0, 1, 2, 20]
    assert candidate([5, 15, 0, 3, -13, -8, 0], 7) == [-13, -8, 0, 0, 3, 5, 15]
    assert candidate([-1, 0, 2, 5, 3, -10], 2) == [3, 5]
    assert candidate([1, 0, 5, -7], 1) == [5]
    assert candidate([4, -4], 2) == [-4, 4]
    assert candidate([-10, 10], 2) == [-10, 10]

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

Runs

❌ Run 1

Start time: 2023-09-01 02:46:36
Duration: 5.26s
Result: Fail

def maximum(arr, k):
    return sorted(arr, reverse=True)[:k]

❌ Run 2

Start time: 2023-09-01 02:49:35
Duration: 5.46s
Result: Fail

def maximum(arr, k):
    return sorted(arr, reverse=True)[:k]

❌ Run 3

Start time: 2023-09-01 02:52:32
Duration: 5.35s
Result: Fail

def maximum(arr, k):
    return sorted(arr, reverse=True)[:k]

❌ Run 4

Start time: 2023-09-01 02:55:25
Duration: 5.67s
Result: Fail

def maximum(arr, k):
    return sorted(arr, reverse=True)[:k]

❌ Run 5

Start time: 2023-09-01 02:58:25
Duration: 4.53s
Result: Fail

def maximum(arr, k):
    return sorted(arr, reverse=True)[:k]

❌ Run 6

Start time: 2023-09-01 03:01:28
Duration: 8.31s
Result: Fail

def maximum(arr, k):
    return sorted(arr, reverse=True)[:k]

❌ Run 7

Start time: 2023-09-01 03:04:28
Duration: 10.55s
Result: Fail

def maximum(arr, k):
    """
    Given an array arr of integers and a positive integer k, return a sorted list 
    of length k with the maximum k numbers in arr.

    Example 1:

        Input: arr = [-3, -4, 5], k = 3
        Output: [-4, -3, 5]

    Example 2:

        Input: arr = [4, -4, 4], k = 2
        Output: [4, 4]

    Example 3:

        Input: arr = [-3, 2, 1, 2, -1, -2, 1], k = 1
        Output: [2]

    Note:
        1. The length of the array will be in the range of [1, 1000].
        2. The elements in the array will be in the range of [-1000, 1000].
        3. 0 <= k <= len(arr)
    """
    return sorted(arr, reverse=True)[:k]

❌ Run 8

Start time: 2023-09-01 03:07:29
Duration: 11.15s
Result: Fail

def maximum(arr, k):
    """
    Given an array arr of integers and a positive integer k, return a sorted list 
    of length k with the maximum k numbers in arr.

    Example 1:

        Input: arr = [-3, -4, 5], k = 3
        Output: [-4, -3, 5]

    Example 2:

        Input: arr = [4, -4, 4], k = 2
        Output: [4, 4]

    Example 3:

        Input: arr = [-3, 2, 1, 2, -1, -2, 1], k = 1
        Output: [2]

    Note:
        1. The length of the array will be in the range of [1, 1000].
        2. The elements in the array will be in the range of [-1000, 1000].
        3. 0 <= k <= len(arr)
    """
    return sorted(arr, reverse=True)[:k]

❌ Run 9

Start time: 2023-09-01 03:10:31
Duration: 3.25s
Result: Fail

def maximum(arr, k):
    return sorted(arr, reverse=True)[:k]

❌ Run 10

Start time: 2023-09-01 03:13:28
Duration: 17.08s
Result: Fail

def maximum(arr, k):
    """
    Given an array arr of integers and a positive integer k, return a sorted list 
    of length k with the maximum k numbers in arr.

    Example 1:

        Input: arr = [-3, -4, 5], k = 3
        Output: [-4, -3, 5]

    Example 2:

        Input: arr = [4, -4, 4], k = 2
        Output: [4, 4]

    Example 3:

        Input: arr = [-3, 2, 1, 2, -1, -2, 1], k = 1
        Output: [2]

    Note:
        1. The length of the array will be in the range of [1, 1000].
        2. The elements in the array will be in the range of [-1000, 1000].
        3. 0 <= k <= len(arr)
    """
    return sorted(arr, reverse=True)[:k]