That math forum link explains the method for solving a single instance of the problem very well- I'd love to see the application of a general algorithm to it. Considering it is a constraints scenario it would be interesting to see if anyone could come up with a way to use Lagrange multipliers and matrix notation to solve an (almost) arbitrary problem of this type. It should make for a very efficient algorithm as the matrix inversions wouldn't take long for such small dimensions. Love to give it a go myself but not much time available atm unfortunately.