[maths problem] Work out a strange average

Thanks @stefano.menci but I’m really interested in the maths behind it.

I need it running in both Python and Lua, so I can’t rely on a library.

I need to specify a minimum, a maximum and a required “average”.

Thanks,