26 lines
384 B
Python
26 lines
384 B
Python
#!/usr/bin/env python3
|
|
|
|
# Fill Input
|
|
input = ""
|
|
|
|
try:
|
|
with open("1.txt", 'r', encoding='utf-8') as file:
|
|
input += file.read()
|
|
except Exception as e:
|
|
print(f"An error occurred: {e}")
|
|
|
|
# Part 1
|
|
print(input.count("(") - input.count(")"))
|
|
|
|
# Part 2
|
|
res = 0
|
|
for i in range(len(input)):
|
|
match input[i]:
|
|
case '(':
|
|
res += 1
|
|
case ')':
|
|
res -= 1
|
|
if res < 0:
|
|
print(i+1)
|
|
break
|