Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Re: Re: Re: Re: Re: amount permutations

by the_0ne (Pilgrim)
on Mar 05, 2004 at 16:36 UTC ( #334276=note: print w/replies, xml ) Need Help??

in reply to Re: Re: Re: Re: Re: amount permutations
in thread amount permutations

Limbic~Region, I work with gr0k and he has to leave for the day, so I'll reply back. I think our example of what we want was fine, but maybe our code confused some people (as you state in your replies). What we are trying to get it is basicly this...

We have...


to be checked. We want to only add up the combinations that are unique. So, what we were ultimately trying to do was generate a list that would give us a way to calculate the unique combinations. Something like this...


So we'd then run through that list applying our values...

A - 10
A+B - 11
A+B+C - 17
A + C - 16 * matches 16 no need to check C+A, etc..
B - 1
B+C - 7
C - 6

So A+C matches what we want. No need to check C+A. Same with if A+B+C matched what we want. No need to check A+C+B, B+C+A, etc... That was our ultimate goal. Of course A B C could easily be 100 long or even more, but left it small for this post. Hopefully that'll clear some things up. Thanks for all help.
  • Comment on Re: Re: Re: Re: Re: Re: amount permutations

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: Re: amount permutations
by Limbic~Region (Chancellor) on Mar 05, 2004 at 16:44 UTC
    I understand that, which is why I said modifying the code would not be difficult to do that. The problem is you seem to want to proceed with using a technique that is producing far more candidates than is necessary. Making a terrible approach more efficient isn't going to make it work.

    Cheers - L~R

    Update: Even with only pulling unique combinations, it does not take long to get to astronimical numbers as pointed out by kvale earlier. Try out the following code.
    #!/usr/bin/perl use strict; use warnings; my $k = $ARGV[0] || 50; my $total = 1; for my $n ( 1 .. $k - 1 ) { if ( $n > $k - $n ) { $total += factorial($k, $n + 1) / factorial( $k - $n ); } else { $total += factorial($k, $k - $n + 1) / factorial( $n ); } } print "Total unique combinations for $k is $total\n"; sub factorial { my ($n, $max, $total) = @_; $total ||= 1; $max ||= 0; return $total if ! $n || $n == $max - 1; @_ = ($n - 1, $max, $total * $n); goto &factorial; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://334276]
[LanX]: hmm reviews have no vote button?
[1nickt]: I use many books for purposes other than that for which they were written: decoration, paperweight, coffee mug coaster on the good table ...
[LanX]: ah Vote button missing on Review threads

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2017-11-17 21:52 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (274 votes). Check out past polls.