Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
eval term in vars of math solution in Clear category for e+pi by veky
import math, itertools
def intersperse(first, *rest):
if rest:
for op in '**', *'*+-/': # pre-sorted
for cont in intersperse(*rest): yield str(first) + op + cont
else: yield str(first)
permutations = [p for k in range(4) for p in sorted(set(itertools.permutations(['e']*2+['pi']*2, k+1)))]
terms = [t for p in permutations for t in intersperse(*p)]
def tryeval(term):
try: return eval(term, vars(math))
except ArithmeticError: return math.nan
def checkio(n: float) -> str:
return next((t for t in terms if math.isclose(tryeval(t), n, abs_tol=1e-10)), None)
July 7, 2023