XP is just a number | |
PerlMonks |
Re: check possible combination of sum using given arrayby bliako (Monsignor) |
on Jul 07, 2019 at 21:42 UTC ( [id://11102519]=note: print w/replies, xml ) | Need Help?? |
Obviously there are quite a few ways to do this including El Bruto (brute force). In a similar problem, optimization problem, the aim is to find a combination of weights to reach a certain total. With the difference that you have integers and any combination is acceptable. I have suggested using genetic algorithms and there is code there to do that. Another way, possibly inefficient, is to use a tree.
EDIT after soonix's comment below: I have added the next if ... statement to my code above like so (so above code now is corrected to give combinations rather than permutations (=order matters)):
bw, bliako
In Section
Seekers of Perl Wisdom
|
|