Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Find combination of numbers whose sum equals X

by choroba (Archbishop)
on Nov 20, 2020 at 09:47 UTC ( #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
Node Status?
node history
Node Type: note [id://11123877]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2021-01-22 03:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?