## 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 unless $cards and $holes; # TODO: more robust error checks # for now let's just assume that the user is sane :) $cards -= $holes; my $tot = $cards + $holes - 1; my $combos = combinations( [ 0 .. $tot - 1 ], $cards ); while ( my $combo = $combos->next() ) { my $hack = '0' x $tot; # total hack! :) for my $c (@$combo) { substr( $hack, $c, 1, '1' ); } say join ', ', map length() + 1, split /0/, $hack, -1; } } #### $ perl buk.pl -c 12 -h 7 | wc -l 462