Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^3: unordered sets of N elements

by dragonchild (Archbishop)
on Jul 13, 2004 at 13:50 UTC ( [id://373989]=note: print w/replies, xml ) Need Help??


in reply to Re^2: unordered sets of N elements
in thread unordered sets of N elements

If you want to solve it recursively, the induction is good. However, I'd use L~R's googled formula with my mod for different number of sides.

Note - none of the formulas help if you have 2d6+2d8 with the same constraint across all four dice.

------
We are the carpenters and bricklayers of the Information Age.

Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

I shouldn't have to say this, but any code, unless otherwise stated, is untested

Replies are listed 'Best First'.
Re^4: unordered sets of N elements
by Limbic~Region (Chancellor) on Jul 13, 2004 at 14:39 UTC
    dragonchild,
    That may be where using one of those nifty CPAN modules and sorting/joining/hashing comes into play.
    #!/usr/bin/perl use strict; use warnings; use Algorithm::Loops 'NestedLoops'; my (@combo, %seen); my %roll = ( 'type1' => { 'sides' => 6, 'count' => 2 }, 'type2' => { 'sides' => 8, 'count' => 2 }, ); my $die = 4; my $iter = NestedLoops( [ map { ( [1..$_->{sides}] ) x $_->{count} } values %roll ], { OnlyWhen => \&ok } ); print "@combo\n" while ( @combo = $iter->() ); sub ok { my $key = join '' , sort @_; return undef if exists $seen{$key} || length $key != $die; $seen{$key} = undef; return 1; }

    Cheers - L~R

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2024-04-16 15:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found