Share code snippets.

42.py

Created 1 year ago by anonymous
42 - reverse any real valued function
import math
E=3
T=40**E
D=10**E

def nu():
	for c in range(-T,T):
		yield c/D

def fu(n):
	r=n**n
	if isinstance(r,float):return r
	else:return ""

def va():
	for n in nu():
		yield fu(n)

def vb():
	for n in nu():
		yield fu(n+1/D)

def d(n):return int(n*D)

def inv(n):
	for a,b,r in zip(va(),vb(),nu()):
		if a=="" or b=="":continue
		if (d(a)<=d(n)<=d(b))or(d(b)<=d(n)<=d(a)):yield d(r)/D

while True:
	i=float(input())
	s=""
	for r in inv(i):
		if fu(r)==i:s+="="
		s+=str(r)
		s+="\n"
	print(s)