Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Safe Code by tokiojapan55
import re
def safe_code(equation):
for n in range(10):
if equation.find(str(n)) == -1:
expression = equation.replace("#", str(n))
for m in re.finditer('\d+', expression):
if len(m.group()) > 1 and m.group()[0] == '0':
expression = ''
break
if expression:
fomula, answer = expression.split("=")
try:
if eval(fomula) == eval(answer):
return n
except:
pass
return -1
June 18, 2021