Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def solve_runes(runes):
- if runes[0] not in ([str(x) for x in range(10)] + ['-'] + ['?'] or ['-+', '-*'] in runes) or runes.startswith('0') or runes.startswith('-0'):
- return -1
- if runes.find('+-') != -1:
- first = runes[:runes.find('+-')]
- operation = '+'
- second = runes[runes.find('+-') + 1:runes.find('=')]
- total = runes[runes.find('=') + 1:]
- elif runes.find('*-') != -1:
- first = runes[:runes.find('*-')]
- operation = '*'
- second = runes[runes.find('*-') + 1:runes.find('=')]
- total = runes[runes.find('=') + 1:]
- elif runes.find('--') != -1:
- first = runes[:runes.find('--')]
- operation = '-'
- second = runes[runes.find('--') + 1:runes.find('=')]
- total = runes[runes.find('=') + 1:]
- elif runes.find('+') != -1:
- first = runes[:runes.find('+')]
- operation = '+'
- second = runes[runes.find('+') + 1:runes.find('=')]
- total = runes[runes.find('=') + 1:]
- elif runes.find('*') != -1:
- first = runes[:runes.find('*')]
- operation = '*'
- second = runes[runes.find('*') + 1:runes.find('=')]
- total = runes[runes.find('=') + 1:]
- elif runes.count('-') == 2:
- first = runes[:runes.rfind('-')]
- operation = '-'
- second = runes[runes.rfind('-') + 1:runes.find('=')]
- total = runes[runes.find('=') + 1:]
- for i in range(10):
- first_for = first.replace('?', str(i), first.count('?'))
- if first_for.startswith('00'):
- break
- second_for = second.replace('?', str(i), second.count('?'))
- if second_for.startswith('00'):
- break
- total_for = total.replace('?', str(i), total.count('?'))
- if total_for.startswith('00'):
- break
- if operation == '+':
- if int(first_for) + int(second_for) == int(total_for):
- return i
- elif operation == '-':
- if int(first_for) - int(second_for) == int(total_for):
- return i
- elif operation== '*':
- if int(first_for) * int(second_for) == int(total_for):
- return i
- return -1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement