This is a solution to FonnD's Puzzle Involving Squares, written in Python 3.

You can run it like this: python3

def validate_inputs(func):
    # This is a decorator to check the function's
    # arguments for negative values. In case of a
    # negative value, a ValueError will be raised.
    def validator(*args):
        for param in args:
            if param < 0:
                raise ValueError("parameter %d is smaller than 0!" % param)
        return func(*args)

    return validator

def square(x):
    # Doing it like this is probably not the most
    # resource-efficient way, but I wanted to
    # demonstrate the elegance of Python.
    return sum([(x-i)**2 for i in range(x)])

def rectangle(x, y):
    return sum([(x-i)*(y-i) for i in range(min(x,y))])

def cube(x):
    return 3*(x+1)*square(x)

def cuboid(x,y,z):
    return (z+1) * rectangle(x,y) + (y+1) * rectangle(x,z) + (x+1) * rectangle(y,z)

print(rectangle(3, 4))

Made by strata, 03feb18 10:36am. Written in the Editor of the Beast.