aoc-2015/day1/so1.py

31 lines
588 B
Python
Raw Normal View History

2020-11-29 20:03:34 +00:00
from functools import reduce
from operator import add
def floor(plan: str):
return reduce(add, [1 if e == '(' else -1 for e in plan])
def test():
assert floor("(())") == 0
assert floor("()()") == 0
assert floor("(((") == 3
assert floor("(()(()(") == 3
assert floor("))(((((") == 3
assert floor("())") == -1
assert floor("))(") == -1
assert floor(")))") == -3
assert floor(")())())") == -3
def solve():
with open("in1") as puzzle:
r = puzzle.read()
return floor(r)
if __name__ == "__main__":
print(f"Floor: {solve()}")