Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
FP & MetaOOP solution in Creative category for Geometry Figures by flpo
from math import pi, sqrt
from functools import partial as p, reduce
from operator import mul, add, sub
compose = lambda g, f: lambda *a: g(f(*a))
pack = lambda f: lambda *a: f(a)
p_mul = p(p, mul)
square = lambda x: x ** 2
mmul = p(reduce, mul)
triangle_area = lambda *a: sqrt(mmul(map(p(sub, sum(a) / 2), ((0,) + a))))
circle_area = compose(p_mul(pi), square)
rectangle_area = mul
pentagon_area = compose(p_mul(sqrt(25 + 10 * sqrt(5)) / 4), square)
hexagon_area = compose(p_mul(3 * sqrt(3) / 2), square)
cube_area = compose(p_mul(6), square)
triangle_perimeter = pack(sum)
circle_perimeter = p_mul(2*pi)
rectangle_perimeter = compose(p_mul(2), add)
pentagon_perimeter = p_mul(5)
hexagon_perimeter = p_mul(6)
cube_perimeter = p_mul(12)
cube_volume = lambda a: a ** 3
class Figure:
def __init__(self, *a): self.n, *self.a = a
__getattr__ = lambda s, a: lambda: round(globals().get(s.n + '_' + a, lambda *_: 0)(*s.a), 2)
June 7, 2018
Comments: