in reply to Re: partition of an array
in thread partition of an array
There are 13 items so we will have one partition of 6 and one of 7. your code produces the following solution:7 7 7 1 0 0 0 -42 0 0 6 6 6
The first partition sums to 7 and the second to -9 with a difference of 16. You could move (not swap) the 6 in the first partion to the second partition and you would end up with:46 : [7 7 7 1 0 0 0] [-42 0 0 6 6 6] 32 : [0 7 7 1 0 0 0] [-42 7 0 6 6 6] 18 : [0 0 7 1 0 0 0] [-42 7 7 6 6 6] 16 : [0 0 6 1 0 0 0] [-42 7 7 7 6 6]
The first partition now sums to 1 and the second to -3 for a difference of 4. I don't know the difficulty in accounting for this situation but the problem is assuming the only balancing operation is swapping.4 : [0 0 1 0 0 0] [-42 7 7 7 6 6 6]
Cheers - L~R
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: partition of an array
by BrowserUk (Patriarch) on Mar 09, 2009 at 19:34 UTC | |
by Limbic~Region (Chancellor) on Mar 09, 2009 at 19:55 UTC | |
by Limbic~Region (Chancellor) on Mar 09, 2009 at 20:09 UTC |