23 lines
No EOL
319 B
Python
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) |