Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Brute Force solution in Clear category for e+pi by StefanPochmann
from math import e, pi
from itertools import product
def checkio(n: float) -> str:
def correct(s):
try:
return abs(eval(s) - n) < 1e-10
except OverflowError:
return False
return min(
s
for k in range(1, 5)
for a in [[None] * (2*k-1)]
for a[::2] in product(['e', 'pi'], repeat=k)
if a.count('e') <= 2 >= a.count('pi')
for a[1::2] in product('+ - * / **'.split(), repeat=k-1)
for s in [''.join(a)]
if correct(s)
)
May 10, 2023
Comments: