I am looking for a way to group numbers into 3 groups, which each group has a sum as close to others as possible. And the order of original list is preserved.
For example , here is a list:
5,7,2,4,3,10 I should group them into (5,7) (2,4,3) (10) the sum for each group is (12) (9) (10)
My initial thought is to add up until one group is greater than Sum/3, then move to next. But the above list will become:
edit: wrong number used, sorry for the error. avg=10.3 groups: (5,72) (4,3,10) ()
I am thinking about adding more conditions to the addup process, But there are always edge cases not covered. As a stubborn programmer, I'd wish to have something working intrinsically correct rather than relying on conditions to cover edge cases.
The original problem: Trying to arrange a number of tables into 3 columns layout without breaking individual tables. Then each column should have similar height. The numbers in the example represent the height of each table.