Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: partition of an array

by irah (Pilgrim)
on Mar 09, 2009 at 05:16 UTC ( [id://749211]=note: print w/replies, xml ) Need Help??


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 ?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://749211]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-19 16:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found