Add 1 -> 5
This commit is contained in:
25
2015/1.py
Normal file
25
2015/1.py
Normal file
@@ -0,0 +1,25 @@
|
||||
#!/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
|
||||
Reference in New Issue
Block a user