in reply to partition of an array

Sample program as follow

use strict; use warnings; use Data::Dumper; my (@string, $length, $half); my (@arr1, @arr2); @string = ( 9,1,6,3 ); @arr1 = splice(@string,0,scalar(@string)/2); print Dumper(\@arr1); print Dumper(\@string);

Replies are listed 'Best First'.
Re^2: partition of an array
by mostvisited (Initiate) on Mar 09, 2009 at 05:50 UTC
    this code would simply divide the array.. but it doesnt take care of the sum condition. As i have mentioned the difference of sum of elements of two new arrays should be minimal. The new partitions should be balanced also. How to maintain that property ?