Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Eval solution in Clear category for Safe Code by Chocolater
def safe_code(equation):
for i in (a for a in range(10) if str(a) not in equation):
new_equation = equation.replace('#', str(i)).split('=')
if new_equation[0][0] != '0':
if str(eval(new_equation[0])) == new_equation[1]:
return i
return -1
if __name__ == '__main__':
print("Example:")
print(safe_code("#3#*4#=34639"))
#These "asserts" using only for self-checking and not necessary for auto-testing
assert safe_code("-5#*-1=5#") == 0
assert safe_code("##*##=302#") == 5
assert safe_code("19--45=5#") == -1
print("Coding complete? Click 'Check' to earn cool rewards!")
Sept. 15, 2018
Comments: