Date: 18 July, 2023
Model: gpt-3.5-turbo
Temperature: 0.2
Passing runs: 10
Total runs: 10
Success rate: 100%
Tokens: 118
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.
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
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("<><><<><>><>>><>")
Start time: 2023-07-18 17:19:33
Duration: 5.25s
Completion tokens: 139
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 bracket in brackets:
if bracket == "<":
stack.append(bracket)
elif bracket == ">":
if len(stack) == 0:
return False
stack.pop()
return len(stack) == 0
Start time: 2023-07-18 17:19:27
Duration: 5.49s
Completion tokens: 139
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 bracket in brackets:
if bracket == "<":
stack.append(bracket)
elif bracket == ">":
if len(stack) == 0:
return False
stack.pop()
return len(stack) == 0
Start time: 2023-07-18 17:19:21
Duration: 5.54s
Completion tokens: 139
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 bracket in brackets:
if bracket == "<":
stack.append(bracket)
elif bracket == ">":
if len(stack) == 0:
return False
stack.pop()
return len(stack) == 0
Start time: 2023-07-18 17:19:16
Duration: 5.35s
Completion tokens: 139
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 bracket in brackets:
if bracket == "<":
stack.append(bracket)
elif bracket == ">":
if len(stack) == 0:
return False
stack.pop()
return len(stack) == 0
Start time: 2023-07-18 17:19:10
Duration: 5.7s
Completion tokens: 139
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 bracket in brackets:
if bracket == "<":
stack.append(bracket)
elif bracket == ">":
if len(stack) == 0:
return False
stack.pop()
return len(stack) == 0
Start time: 2023-07-18 17:19:04
Duration: 6.12s
Completion tokens: 139
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 bracket in brackets:
if bracket == "<":
stack.append(bracket)
elif bracket == ">":
if len(stack) == 0:
return False
stack.pop()
return len(stack) == 0
Start time: 2023-07-18 17:18:58
Duration: 5.64s
Completion tokens: 139
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 bracket in brackets:
if bracket == "<":
stack.append(bracket)
elif bracket == ">":
if len(stack) == 0:
return False
stack.pop()
return len(stack) == 0
Start time: 2023-07-18 17:18:54
Duration: 4.56s
Completion tokens: 135
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 bracket in brackets:
if bracket == "<":
stack.append(bracket)
elif bracket == ">":
if not stack:
return False
stack.pop()
return len(stack) == 0
Start time: 2023-07-18 17:18:48
Duration: 5.87s
Completion tokens: 139
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 bracket in brackets:
if bracket == "<":
stack.append(bracket)
elif bracket == ">":
if len(stack) == 0:
return False
stack.pop()
return len(stack) == 0
Start time: 2023-07-18 17:18:44
Duration: 4.13s
Completion tokens: 139
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 bracket in brackets:
if bracket == "<":
stack.append(bracket)
elif bracket == ">":
if len(stack) == 0:
return False
stack.pop()
return len(stack) == 0