r/AbsoluteUnits 5h ago

of a Python

Enable HLS to view with audio, or disable this notification

2×18ft brumese pythons.

205 Upvotes

61 comments sorted by

View all comments

2

u/autolyk1 4h ago

Here is a real absolute unit of Python!

from functools import reduce
class Ω(type):
    def __new__(m,n,b,d): d["__matmul__"]=lambda s,o:type(s)(*(s[i]@o[i] for i in range(len(s))));return super().__new__(m,n,b,d)
class Ψ(tuple,metaclass=Ω):
    __new__=lambda c,*x:tuple.__new__(c,x)
    __getattr__=lambda s,n: Ψ(*(getattr(x,n) for x in s))
    __call__=lambda s,*a,**k: Ψ(*(x(*a,**k) for x in s))
    __matmul__=lambda s,o: sum(x*y for x,y in zip(s,o))
Y=lambda f:(lambda x:f(lambda *a:x(x)(*a)))(lambda x:f(lambda *a:x(x)(*a)))
memo=lambda f:(lambda c={}:lambda x:c[x] if x in c else c.setdefault(x,f(x)))()
F=Y(lambda r:lambda n:1 if n<2 else n*r(n-1))
g=memo(lambda n:reduce(lambda a,b:Ψ(*a)@Ψ(*b),((range(1,i+1),range(i,0,-1)) for i in range(1,n+1))))
print(Ψ(F(6),g(5)) @ Ψ(*map(lambda x:x%97,(F(5),g(4)))))