Files
aoc/2015/1.py
PedroEdiaz 62dade14e1 Add 1 -> 5
2025-10-29 17:19:47 -06:00

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