Non mathematicians solution to this problem.  Brute force and not at all optimised