advent-of-code/2015/day01.py

31 lines
566 B
Python
Raw Normal View History

2022-12-09 21:41:14 +00:00
import shared
from collections import Counter
def pt1(inp):
floor = 0
chars = [x for x in inp]
c = Counter(chars)
floor += c['(']
floor -= c[')']
print(floor)
def pt2(inp):
floor = 0
chars = [x for x in inp]
for idx, c in enumerate(chars):
if c == '(':
floor +=1
if c == ')':
floor -= 1
if floor == -1:
print(idx+1)
break
if __name__ == "__main__":
with open(shared.get_fname(1), "r") as f:
inp = f.read().rstrip()
pt1(inp)
pt2(inp)