18 lines
406 B
Python
18 lines
406 B
Python
def basement_pos(plan: str):
|
|
f = 0
|
|
for i,e in enumerate(plan):
|
|
f = f+1 if e == '(' else f-1
|
|
if f == -1:
|
|
return i+1
|
|
|
|
def test():
|
|
assert basement_pos(")") == 1
|
|
assert basement_pos("()())") == 5
|
|
|
|
def solve():
|
|
with open("in2") as puzzle:
|
|
r = puzzle.read()
|
|
return basement_pos(r)
|
|
|
|
if __name__ == "__main__":
|
|
print(f"Basement position: {solve()}")
|