But the maths to do those calculations I feel are more code hungry than just sorting...

Ioannis