advent-of-code/2015/1/d1.py
2022-12-03 10:41:47 +01:00

23 lines
No EOL
319 B
Python

"""
sum up coded instruction
"""
with open('directions.txt') as filein:
text = filein.read()
translation = {
'(':1,
')':-1
}
print(sum([translation.get(c,0) for c in text]))
"""
stop at given value
"""
s = 0
for i,c in enumerate(text, start=1):
s += translation[c]
if s<0:
break
print(i)