Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
22-liner: esreveR solution in Clear category for Reverse Engineer by przemyslaw.daniel
def verify(expr, x, y):
from fractions import Fraction
try:
out = eval(expr, {"x": Fraction(x), "y": Fraction(y)})
return [out.numerator, out.denominator]
except ZeroDivisionError:
return "ZeroDivisionError"
def gen_expr(depth):
from itertools import product
return ["(%s%s%s)" % (x, o, y) for x, o, y in product(gen_expr(depth-1),
list("+-/*"), gen_expr(depth-1))] if depth else ["x-x", "x", "y"]
def checkio(steps, counter=0):
from random import randint as rnd
while True:
for e in gen_expr(counter):
if all(verify(e, x, y) == val for x, y, val in steps):
return e, rnd(-100, 100), rnd(-100, 100)
counter += 1
Feb. 6, 2017