Skip to content

Latest commit

 

History

History
364 lines (350 loc) · 9.28 KB

File metadata and controls

364 lines (350 loc) · 9.28 KB

Results of Code LLama 34B on HumanEval/56

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

Prompt

def correct_bracketing(brackets: str):
    """ brackets is a string of "<" and ">".
    return True if every opening bracket has a corresponding closing bracket.

    >>> correct_bracketing("<")
    False
    >>> correct_bracketing("<>")
    True
    >>> correct_bracketing("<<><>>")
    True
    >>> correct_bracketing("><<>")
    False
    """

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

Correct solution

def correct_bracketing(brackets: str):
    """ brackets is a string of "<" and ">".
    return True if every opening bracket has a corresponding closing bracket.

    >>> correct_bracketing("<")
    False
    >>> correct_bracketing("<>")
    True
    >>> correct_bracketing("<<><>>")
    True
    >>> correct_bracketing("><<>")
    False
    """depth = 0
    for b in brackets:
        if b == "<":
            depth += 1
        else:
            depth -= 1
        if depth < 0:
            return False
    return depth == 0

Unit tests

METADATA = {}


def check(candidate):
    assert candidate("<>")
    assert candidate("<<><>>")
    assert candidate("<><><<><>><>")
    assert candidate("<><><<<><><>><>><<><><<>>>")
    assert not candidate("<<<><>>>>")
    assert not candidate("><<>")
    assert not candidate("<")
    assert not candidate("<<<<")
    assert not candidate(">")
    assert not candidate("<<>")
    assert not candidate("<><><<><>><>><<>")
    assert not candidate("<><><<><>><>>><>")

Runs

✅ Run 1

Start time: 2023-09-01 02:47:47
Duration: 10.15s
Result: Pass

def correct_bracketing(brackets: str):
    """ brackets is a string of "<" and ">".
    return True if every opening bracket has a corresponding closing bracket.

    >>> correct_bracketing("<")
    False
    >>> correct_bracketing("<>")
    True
    >>> correct_bracketing("<<><>>")
    True
    >>> correct_bracketing("><<>")
    False
    """
    opening_brackets = ["<"]
    closing_brackets = [">"]
    stack = []
    for bracket in brackets:
        if bracket in opening_brackets:
            stack.append(bracket)
        elif bracket in closing_brackets:
            if len(stack) == 0:
                return False
            top = stack.pop()
            if opening_brackets.index(top) != closing_brackets.index(bracket):
                return False
    return len(stack) == 0

✅ Run 2

Start time: 2023-09-01 02:50:48
Duration: 8.32s
Result: Pass

def correct_bracketing(brackets: str):
    """ brackets is a string of "<" and ">".
    return True if every opening bracket has a corresponding closing bracket.

    >>> correct_bracketing("<")
    False
    >>> correct_bracketing("<>")
    True
    >>> correct_bracketing("<<><>>")
    True
    >>> correct_bracketing("><<>")
    False
    """
    opening_brackets = 0
    for char in brackets:
        if char == "<":
            opening_brackets += 1
        elif char == ">":
            opening_brackets -= 1
            if opening_brackets < 0:
                return False
    return opening_brackets == 0

✅ Run 3

Start time: 2023-09-01 02:53:42
Duration: 8.64s
Result: Pass

def correct_bracketing(brackets: str):
    """ brackets is a string of "<" and ">".
    return True if every opening bracket has a corresponding closing bracket.

    >>> correct_bracketing("<")
    False
    >>> correct_bracketing("<>")
    True
    >>> correct_bracketing("<<><>>")
    True
    >>> correct_bracketing("><<>")
    False
    """
    stack = []
    for char in brackets:
        if char == "<":
            stack.append(char)
        elif char == ">":
            if len(stack) == 0:
                return False
            stack.pop()
    return len(stack) == 0

✅ Run 4

Start time: 2023-09-01 02:56:42
Duration: 8.75s
Result: Pass

def correct_bracketing(brackets: str):
    """ brackets is a string of "<" and ">".
    return True if every opening bracket has a corresponding closing bracket.

    >>> correct_bracketing("<")
    False
    >>> correct_bracketing("<>")
    True
    >>> correct_bracketing("<<><>>")
    True
    >>> correct_bracketing("><<>")
    False
    """
    opening_brackets = 0
    for char in brackets:
        if char == "<":
            opening_brackets += 1
        elif char == ">":
            opening_brackets -= 1
            if opening_brackets < 0:
                return False
    return opening_brackets == 0

✅ Run 5

Start time: 2023-09-01 02:59:40
Duration: 8.01s
Result: Pass

def correct_bracketing(brackets: str):
    """ brackets is a string of "<" and ">".
    return True if every opening bracket has a corresponding closing bracket.

    >>> correct_bracketing("<")
    False
    >>> correct_bracketing("<>")
    True
    >>> correct_bracketing("<<><>>")
    True
    >>> correct_bracketing("><<>")
    False
    """
    stack = []
    for char in brackets:
        if char == "<":
            stack.append(char)
        elif char == ">":
            if len(stack) == 0:
                return False
            stack.pop()
    return len(stack) == 0

✅ Run 6

Start time: 2023-09-01 03:02:40
Duration: 10.44s
Result: Pass

def correct_bracketing(brackets: str):
    """ brackets is a string of "<" and ">".
    return True if every opening bracket has a corresponding closing bracket.

    >>> correct_bracketing("<")
    False
    >>> correct_bracketing("<>")
    True
    >>> correct_bracketing("<<><>>")
    True
    >>> correct_bracketing("><<>")
    False
    """
    opening_brackets = ["<"]
    closing_brackets = [">"]
    stack = []
    for bracket in brackets:
        if bracket in opening_brackets:
            stack.append(bracket)
        elif bracket in closing_brackets:
            if len(stack) == 0:
                return False
            top = stack.pop()
            if opening_brackets.index(top) != closing_brackets.index(bracket):
                return False
    return len(stack) == 0

✅ Run 7

Start time: 2023-09-01 03:05:43
Duration: 8.42s
Result: Pass

def correct_bracketing(brackets: str):
    """ brackets is a string of "<" and ">".
    return True if every opening bracket has a corresponding closing bracket.

    >>> correct_bracketing("<")
    False
    >>> correct_bracketing("<>")
    True
    >>> correct_bracketing("<<><>>")
    True
    >>> correct_bracketing("><<>")
    False
    """
    stack = []
    for char in brackets:
        if char == "<":
            stack.append(char)
        elif char == ">":
            if len(stack) == 0:
                return False
            stack.pop()
    return len(stack) == 0

✅ Run 8

Start time: 2023-09-01 03:08:46
Duration: 10.43s
Result: Pass

def correct_bracketing(brackets: str):
    """ brackets is a string of "<" and ">".
    return True if every opening bracket has a corresponding closing bracket.

    >>> correct_bracketing("<")
    False
    >>> correct_bracketing("<>")
    True
    >>> correct_bracketing("<<><>>")
    True
    >>> correct_bracketing("><<>")
    False
    """
    opening_brackets = ["<"]
    closing_brackets = [">"]
    stack = []
    for bracket in brackets:
        if bracket in opening_brackets:
            stack.append(bracket)
        elif bracket in closing_brackets:
            if len(stack) == 0:
                return False
            top = stack.pop()
            if opening_brackets.index(top) != closing_brackets.index(bracket):
                return False
    return len(stack) == 0

✅ Run 9

Start time: 2023-09-01 03:11:43
Duration: 10.31s
Result: Pass

def correct_bracketing(brackets: str):
    """ brackets is a string of "<" and ">".
    return True if every opening bracket has a corresponding closing bracket.

    >>> correct_bracketing("<")
    False
    >>> correct_bracketing("<>")
    True
    >>> correct_bracketing("<<><>>")
    True
    >>> correct_bracketing("><<>")
    False
    """
    opening_brackets = ["<"]
    closing_brackets = [">"]
    stack = []
    for bracket in brackets:
        if bracket in opening_brackets:
            stack.append(bracket)
        elif bracket in closing_brackets:
            if len(stack) == 0:
                return False
            top = stack.pop()
            if opening_brackets.index(top) != closing_brackets.index(bracket):
                return False
    return len(stack) == 0

✅ Run 10

Start time: 2023-09-01 03:14:44
Duration: 8.53s
Result: Pass

def correct_bracketing(brackets: str):
    """ brackets is a string of "<" and ">".
    return True if every opening bracket has a corresponding closing bracket.

    >>> correct_bracketing("<")
    False
    >>> correct_bracketing("<>")
    True
    >>> correct_bracketing("<<><>>")
    True
    >>> correct_bracketing("><<>")
    False
    """
    opening_brackets = 0
    for char in brackets:
        if char == "<":
            opening_brackets += 1
        elif char == ">":
            opening_brackets -= 1
            if opening_brackets < 0:
                return False
    return opening_brackets == 0