Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Brute solution in Clear category for Reverse Engineer by veky
def expr(cxity):
if not cxity:
yield "x"
yield "y"
for k in range(cxity):
for a in expr(k):
for b in expr(cxity - k - 1):
for op in "+-*/":
yield "(" + a + op + b + ")"
def allexpr(start=0):
while True:
yield from expr(start)
start += 1
def eeval(e, x, y):
from fractions import Fraction as F
try:
r = eval(e, {"x": F(x), "y": F(y)})
except ZeroDivisionError as zd:
return zd.__class__.__name__
else:
return [r.numerator, r.denominator]
def pairs(tot):
while True:
for i in range(tot):
yield i, tot - i
tot += 1
genpairs = pairs(1)
def checkio(steps):
global genexpr
if not steps:
genexpr = allexpr()
while True:
e = next(genexpr)
if all(eeval(e, x, y) == r for x, y, r in steps):
i, j = next(genpairs)
return e, i, j
March 5, 2014
Comments: