Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Find combination of numbers whose sum equals X

by choroba (Cardinal)
on Nov 20, 2020 at 09:47 UTC ( [id://11123877]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    #!/usr/bin/perl
    use warnings;
    ...
    
    cmp_deeply summands(100, 5, 5, 5, 5, 10, 15, 80, 99),
        bag([5, 15, 80], [5, 5, 5, 5, 80], [5, 5, 10, 80]);
    
  2. or download this
    use Memoize;
    memoize('_summands');
    
  3. or download this
            my $number = $numbers[$index];
            my @remaining = @numbers[ grep $_ != $index, 0 .. $#numbers ];
    
  4. or download this
            my @remaining = @numbers;
            my ($number) = splice @remaining, $index, 1;
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-25 11:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found