in reply to Combinatorics problem. (Updated with more info.)

Argh, i'm damn slow.. i was sure the answer was in the Tartaglia's triangle, but no way.

here my, plain as usual, solution:
use strict; use warnings; my @posts = (1..$ARGV[0] || 5); my @pigeons = (1..$ARGV[1] || 3); print +('1 ' x @pigeons)."\n" if @posts == @pigeons; die sprintf "%s is not enought for %s pigeons!",scalar @posts,scalar +@pigeons if @pigeons > @posts; for (@pigeons) { my $max = @posts - @pigeons + 1; while ($max > 1){ my @distr = (0) x ($#pigeons+1); $distr[0] = $max; my $remain = @posts - $max; my $i=0; while ($remain > 0){ $i == $#distr ? $i=1 : $i++; $distr[$i]++; $remain--; } $max--; print +(map{ "$distr[$_-1] "} @pigeons),"\n"; } @pigeons = (pop @pigeons,@pigeons); } __DATA__ perl BUk-pigeons.pl 5 3 3 1 1 2 2 1 1 3 1 1 2 2 1 1 3 2 1 2
thanks for the amusement!
At the end of writing i was surpised i needed not an hash to get uniques results..

L*

UPDATE: sadly my solutions gives too few combinations.. perl BUk-pigeons.pl 12 7 | wc -l give me only 35 combinations..
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.