Skip to content

Instantly share code, notes, and snippets.

@nansenat16
Last active July 31, 2018 11:06
Show Gist options
  • Save nansenat16/7affef5ed5eaaad8be8e753eee56dbec to your computer and use it in GitHub Desktop.
Save nansenat16/7affef5ed5eaaad8be8e753eee56dbec to your computer and use it in GitHub Desktop.
stdin=["44+44=88","4+6=10","6-2=4","2-6=?","6-3=2"]
total=0
for line in stdin:
data=list(line)
if('?' in data):
total+=0
elif('+' in data):
a=''.join(data[0:data.index('+')])
b=''.join(data[data.index('+')+1:data.index('=')])
d=int(a)+int(b)
data1=data[::-1]
c=data1[0:data1.index('=')]
e=''.join(c[::-1])
if d==int(e):
total+=1
elif('-' in data):
a=''.join(data[0:data.index('-')])
b=''.join(data[data.index('-')+1:data.index('=')])
d=int(a)-int(b)
data1=data[::-1]
c=data1[0:data1.index('=')]
e=''.join(c[::-1])
if d==int(e):
total+=1
elif('@@@' in data):
total+=0
print total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment