I'm trying to split an array of numbers into two separate arrays that have their sum as close together as possible (I need this for evening out the heights of data in a collection view). My idea is that to do this, I would find all possible arrays I can generate from this initial array. The final arrays would always have an equal length, except for the case where the initial array consists of an odd number of items. If that's the case, one of the final arrays will have one more item.
Sample input: [15,23,13,5,12,18,4,11]
Sample output: [12,23,4,11]
and [15,18,13,5]
(at least I think the sums of 50 and 51 are as close as we're going to get here)
I have tried a lot of code but it's pretty rubbish and is not going to be of help here. With any pointers in terms of which algorithm I'm looking for, I should be able to solve this myself.
I've tried to no avail, and any pointers to algorithms or help as to how to do this are welcome. Thanks!