2015: d01: ex2: add solution

This commit is contained in:
Bruno BELANYI 2025-05-21 00:39:52 +01:00
parent 8c3207a385
commit c6afe68ac5

22
2015/d01/ex2/ex2.py Executable file
View file

@ -0,0 +1,22 @@
#!/usr/bin/env python
import sys
def solve(input: str) -> int:
BASEMENT = -1
current = 0
for i, c in enumerate(input, start=1):
current += 1 if c == "(" else -1
if current == BASEMENT:
return i
assert False # Sanity check
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()