Quote Originally Posted by William444555 View Post
What sort of "playing" did you do as I have tried may ways and all seem to get way off.
As others have said, we REALLY need to know the context of the question. You originally gave the impression that you just need to work it out for this one set of numbers, but now you say you want a general algorithm. Do you mean you want to program it, or something else? In any case, what are the details of the more general question, and why do you need to do it? If it is for an assignment, quote exactly what you are to do. If it is just for you, tell us why.

As to what I did, I made a spreadsheet in which I first sorted the numbers, then could enter 1, 2, or 3 next to each of them, which would put it into a column that would be added up and compared to the goal. I initially assigned the numbers 1, 2, 3, 1, 2, 3, ..., and then looked for pairs I could interchange to get closer to the goal. Eventually I couldn't directly improve it, so I would just change some pair to "shake up" the problem and hopefully get on a path to a better solution. This is just a heuristic, not an algorithm; but it might be necessary to take such an approach, since there are otherwise quadrillions of possible partitions to try. (But only a complete search could prove that you have the best possible answer, if you can't find one that is as close as possible like mine.)

My starting with alternating columns was important, as it ensured that there would be numbers close to one another in all three columns, so that I could interchange pairs to make small adjustments.