Skip to content

Latest commit

 

History

History
339 lines (313 loc) · 10.6 KB

136.md

File metadata and controls

339 lines (313 loc) · 10.6 KB

Results of GPT-4 on HumanEval/136

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

Prompt

Tokens: 164

def largest_smallest_integers(lst):
    '''
    Create a function that returns a tuple (a, b), where 'a' is
    the largest of negative integers, and 'b' is the smallest
    of positive integers in a list.
    If there is no negative or positive integers, return them as None.

    Examples:
    largest_smallest_integers([2, 4, 1, 3, 5, 7]) == (None, 1)
    largest_smallest_integers([]) == (None, None)
    largest_smallest_integers([0]) == (None, None)
    '''

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

Correct solution

def largest_smallest_integers(lst):
    '''
    Create a function that returns a tuple (a, b), where 'a' is
    the largest of negative integers, and 'b' is the smallest
    of positive integers in a list.
    If there is no negative or positive integers, return them as None.

    Examples:
    largest_smallest_integers([2, 4, 1, 3, 5, 7]) == (None, 1)
    largest_smallest_integers([]) == (None, None)
    largest_smallest_integers([0]) == (None, None)
    '''smallest = list(filter(lambda x: x < 0, lst))
    largest = list(filter(lambda x: x > 0, lst))
    return (max(smallest) if smallest else None, min(largest) if largest else None)

Unit tests

def check(candidate):

    # Check some simple cases
    assert candidate([2, 4, 1, 3, 5, 7]) == (None, 1)
    assert candidate([2, 4, 1, 3, 5, 7, 0]) == (None, 1)
    assert candidate([1, 3, 2, 4, 5, 6, -2]) == (-2, 1)
    assert candidate([4, 5, 3, 6, 2, 7, -7]) == (-7, 2)
    assert candidate([7, 3, 8, 4, 9, 2, 5, -9]) == (-9, 2)
    assert candidate([]) == (None, None)
    assert candidate([0]) == (None, None)
    assert candidate([-1, -3, -5, -6]) == (-1, None)
    assert candidate([-1, -3, -5, -6, 0]) == (-1, None)
    assert candidate([-6, -4, -4, -3, 1]) == (-3, 1)
    assert candidate([-6, -4, -4, -3, -100, 1]) == (-3, 1)

    # Check some edge cases that are easy to work out by hand.
    assert True

Runs

✅ Run 1

Start time: 2023-07-18 17:57:09
Duration: 22.04s
Completion tokens: 186
Result: Pass

def largest_smallest_integers(lst):
    '''
    Create a function that returns a tuple (a, b), where 'a' is
    the largest of negative integers, and 'b' is the smallest
    of positive integers in a list.
    If there is no negative or positive integers, return them as None.

    Examples:
    largest_smallest_integers([2, 4, 1, 3, 5, 7]) == (None, 1)
    largest_smallest_integers([]) == (None, None)
    largest_smallest_integers([0]) == (None, None)
    '''
    neg = [i for i in lst if i < 0]
    pos = [i for i in lst if i > 0]
    return (max(neg) if neg else None, min(pos) if pos else None)

✅ Run 2

Start time: 2023-07-18 17:56:52
Duration: 17.14s
Completion tokens: 199
Result: Pass

def largest_smallest_integers(lst):
    '''
    Create a function that returns a tuple (a, b), where 'a' is
    the largest of negative integers, and 'b' is the smallest
    of positive integers in a list.
    If there is no negative or positive integers, return them as None.

    Examples:
    largest_smallest_integers([2, 4, 1, 3, 5, 7]) == (None, 1)
    largest_smallest_integers([]) == (None, None)
    largest_smallest_integers([0]) == (None, None)
    '''
    negatives = [i for i in lst if i < 0]
    positives = [i for i in lst if i > 0]
    a = max(negatives) if negatives else None
    b = min(positives) if positives else None
    return (a, b)

✅ Run 3

Start time: 2023-07-18 17:56:30
Duration: 21.38s
Completion tokens: 238
Result: Pass

def largest_smallest_integers(lst):
    '''
    Create a function that returns a tuple (a, b), where 'a' is
    the largest of negative integers, and 'b' is the smallest
    of positive integers in a list.
    If there is no negative or positive integers, return them as None.

    Examples:
    largest_smallest_integers([2, 4, 1, 3, 5, 7]) == (None, 1)
    largest_smallest_integers([]) == (None, None)
    largest_smallest_integers([0]) == (None, None)
    '''
    if not lst:
        return (None, None)
    else:
        negatives = [num for num in lst if num < 0]
        positives = [num for num in lst if num > 0]
        if negatives and positives:
            return (max(negatives), min(positives))
        elif negatives:
            return (max(negatives), None)
        elif positives:
            return (None, min(positives))
        else:
            return (None, None)

✅ Run 4

Start time: 2023-07-18 17:56:12
Duration: 18.45s
Completion tokens: 218
Result: Pass

def largest_smallest_integers(lst):
    '''
    Create a function that returns a tuple (a, b), where 'a' is
    the largest of negative integers, and 'b' is the smallest
    of positive integers in a list.
    If there is no negative or positive integers, return them as None.

    Examples:
    largest_smallest_integers([2, 4, 1, 3, 5, 7]) == (None, 1)
    largest_smallest_integers([]) == (None, None)
    largest_smallest_integers([0]) == (None, None)
    '''
    if not lst:
        return (None, None)
    
    negatives = [num for num in lst if num < 0]
    positives = [num for num in lst if num > 0]
    
    largest_negative = max(negatives) if negatives else None
    smallest_positive = min(positives) if positives else None
    
    return (largest_negative, smallest_positive)

✅ Run 5

Start time: 2023-07-18 17:55:53
Duration: 18.6s
Completion tokens: 238
Result: Pass

def largest_smallest_integers(lst):
    '''
    Create a function that returns a tuple (a, b), where 'a' is
    the largest of negative integers, and 'b' is the smallest
    of positive integers in a list.
    If there is no negative or positive integers, return them as None.

    Examples:
    largest_smallest_integers([2, 4, 1, 3, 5, 7]) == (None, 1)
    largest_smallest_integers([]) == (None, None)
    largest_smallest_integers([0]) == (None, None)
    '''
    if not lst:
        return (None, None)
    
    negatives = [i for i in lst if i < 0]
    positives = [i for i in lst if i > 0]
    
    if not negatives:
        largest_negative = None
    else:
        largest_negative = max(negatives)
        
    if not positives:
        smallest_positive = None
    else:
        smallest_positive = min(positives)
        
    return (largest_negative, smallest_positive)

✅ Run 6

Start time: 2023-07-18 17:55:38
Duration: 15.33s
Completion tokens: 186
Result: Pass

def largest_smallest_integers(lst):
    '''
    Create a function that returns a tuple (a, b), where 'a' is
    the largest of negative integers, and 'b' is the smallest
    of positive integers in a list.
    If there is no negative or positive integers, return them as None.

    Examples:
    largest_smallest_integers([2, 4, 1, 3, 5, 7]) == (None, 1)
    largest_smallest_integers([]) == (None, None)
    largest_smallest_integers([0]) == (None, None)
    '''
    neg = [i for i in lst if i < 0]
    pos = [i for i in lst if i > 0]
    return (max(neg) if neg else None, min(pos) if pos else None)

✅ Run 7

Start time: 2023-07-18 17:55:16
Duration: 21.62s
Completion tokens: 223
Result: Pass

def largest_smallest_integers(lst):
    '''
    Create a function that returns a tuple (a, b), where 'a' is
    the largest of negative integers, and 'b' is the smallest
    of positive integers in a list.
    If there is no negative or positive integers, return them as None.

    Examples:
    largest_smallest_integers([2, 4, 1, 3, 5, 7]) == (None, 1)
    largest_smallest_integers([]) == (None, None)
    largest_smallest_integers([0]) == (None, None)
    '''
    negatives = [i for i in lst if i < 0]
    positives = [i for i in lst if i > 0]

    if negatives and positives:
        return (max(negatives), min(positives))
    elif negatives:
        return (max(negatives), None)
    elif positives:
        return (None, min(positives))
    else:
        return (None, None)

✅ Run 8

Start time: 2023-07-18 17:55:00
Duration: 16.07s
Completion tokens: 199
Result: Pass

def largest_smallest_integers(lst):
    '''
    Create a function that returns a tuple (a, b), where 'a' is
    the largest of negative integers, and 'b' is the smallest
    of positive integers in a list.
    If there is no negative or positive integers, return them as None.

    Examples:
    largest_smallest_integers([2, 4, 1, 3, 5, 7]) == (None, 1)
    largest_smallest_integers([]) == (None, None)
    largest_smallest_integers([0]) == (None, None)
    '''
    negatives = [i for i in lst if i < 0]
    positives = [i for i in lst if i > 0]
    a = max(negatives) if negatives else None
    b = min(positives) if positives else None
    return (a, b)

✅ Run 9

Start time: 2023-07-18 17:54:44
Duration: 15.27s
Completion tokens: 199
Result: Pass

def largest_smallest_integers(lst):
    '''
    Create a function that returns a tuple (a, b), where 'a' is
    the largest of negative integers, and 'b' is the smallest
    of positive integers in a list.
    If there is no negative or positive integers, return them as None.

    Examples:
    largest_smallest_integers([2, 4, 1, 3, 5, 7]) == (None, 1)
    largest_smallest_integers([]) == (None, None)
    largest_smallest_integers([0]) == (None, None)
    '''
    negatives = [i for i in lst if i < 0]
    positives = [i for i in lst if i > 0]
    a = max(negatives) if negatives else None
    b = min(positives) if positives else None
    return (a, b)

✅ Run 10

Start time: 2023-07-18 17:54:24
Duration: 20.5s
Completion tokens: 232
Result: Pass

def largest_smallest_integers(lst):
    '''
    Create a function that returns a tuple (a, b), where 'a' is
    the largest of negative integers, and 'b' is the smallest
    of positive integers in a list.
    If there is no negative or positive integers, return them as None.

    Examples:
    largest_smallest_integers([2, 4, 1, 3, 5, 7]) == (None, 1)
    largest_smallest_integers([]) == (None, None)
    largest_smallest_integers([0]) == (None, None)
    '''

    negative_integers = [i for i in lst if i < 0]
    positive_integers = [i for i in lst if i > 0]

    if not negative_integers:
        largest_negative = None
    else:
        largest_negative = max(negative_integers)

    if not positive_integers:
        smallest_positive = None
    else:
        smallest_positive = min(positive_integers)

    return (largest_negative, smallest_positive)