Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^3: Combinatorics problem.

by Anonymous Monk
on Dec 11, 2015 at 11:37 UTC ( [id://1150017]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Combinatorics problem.
in thread Combinatorics problem. (Updated with more info.)

okay, less of a hack :)
## usage example: ## program.pl -cards 5 -holes 3 use strict; use warnings; use feature 'say'; use Getopt::Long; use Algorithm::Combinatorics 'combinations'; main(); exit 0; sub main { GetOptions( 'cards=i' => \my $cards, 'holes=i' => \my $holes ); die "Usage: $0 -c CARDS -h HOLES\n" if !defined($cards) || !defined($holes) || $cards <= 0 || $holes <= 0 || $cards < $holes; $cards -= $holes; my $tot = $cards + $holes - 1; my $combos = combinations( [ 0 .. $tot - 1 ], $cards ); while ( my $combo = $combos->next() ) { my @result = (1) x $holes; for my $i ( 0 .. @$combo - 1 ) { $result[ $combo->[$i] - $i ] += 1; } say join ', ', @result; } }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2024-04-19 10:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found