advent-of-code/2015/python/day01.py
2022-12-18 23:55:45 -05:00

31 lines
566 B
Python

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)