Date: 18 July, 2023
Model: gpt-4
Temperature: 0.2
Passing runs: 10
Total runs: 10
Success rate: 100%
Tokens: 115
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 18:32:07
Duration: 10.25s
Completion tokens: 137
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 18:31:58
Duration: 9.44s
Completion tokens: 137
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 18:31:44
Duration: 13.14s
Completion tokens: 137
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 18:31:29
Duration: 15.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 not stack or stack.pop() != '(':
return False
return len(stack) == 0
Start time: 2023-07-18 18:31:19
Duration: 9.87s
Completion tokens: 137
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 18:31:09
Duration: 10.6s
Completion tokens: 137
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 18:30:58
Duration: 10.84s
Completion tokens: 137
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 18:30:45
Duration: 12.67s
Completion tokens: 133
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 not stack
Start time: 2023-07-18 18:30:28
Duration: 17.25s
Completion tokens: 137
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 18:30:15
Duration: 12.78s
Completion tokens: 137
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