2015: d01: ex2: add solution
This commit is contained in:
parent
8c3207a385
commit
c6afe68ac5
1 changed files with 22 additions and 0 deletions
22
2015/d01/ex2/ex2.py
Executable file
22
2015/d01/ex2/ex2.py
Executable 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()
|
||||
Loading…
Add table
Add a link
Reference in a new issue