aoc-2015/day1/so2.py

19 lines
406 B
Python
Raw Normal View History

2020-11-29 20:03:34 +00:00
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()}")