I have an array having some interger elements. I have to split into 2 subsets. Need to verify that sum of these 2 subsets are equal or not. Subset size is not matter, it can be element count of 3,2 or 1,4 or any but should be in 2 part. For example...
Ex 1:
@a1 = qw(1, 3, 8, 4);
This array can be divided into to subsets (1,3,4)=8 and (8)=8, so these two have equal sum.
Ex 2:
@a1 = qw(1, 6, 2);
This cant be divided into two subsets of equal sum.Because (1,6)!=2 or any combination of a subset is not matching to another subset.
I tried below code but it is working for one set of iteration, actually it should check all possible set of iteration to find possiblities.
my @array= qw(1 3 5 7);
my @array= qw(1 3 5 7);
&test(\@array);
sub test
{
my ($s1,$s2);
my @a=@{$_[0]};
for (my $i=0;$i<=$#a ;$i++) {
($s1,$s2)=0;
for (my $j=0;$j<=$#a ;$j++) {
if ($i == $j) {
$s1=$s1+ $a[$j];
}
else{
$s2+=$a[$j];
}
}
}
print "\n";
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
 a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)

For: 

Use: 
 &   & 
 <   < 
 >   > 
 [   [ 
 ]   ] 
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.

