#! perl use strict; use warnings; use constant { WILDCARDS => 9, CHARACTERS => 10, }; my @table = [ 0 .. WILDCARDS ]; for my $char (1 .. CHARACTERS) { push @{ $table[$char] }, $char; push @{ $table[$char] }, combinations($char, $_) for 1 .. WILDCARDS; } my @widths = map { length } @{ $table[-1] }; print "\n"; printf '%*s|', $widths[$_], ($_ || '') for @{ $table[0] }; print "\n"; printf '%s+', ('-' x $_) for @widths; print "\n"; for my $row (1 .. CHARACTERS) { printf '%*d|', $widths[$_], $table[$row][$_] for 0 .. WILDCARDS; print "\n"; } sub combinations { my ($c, $w) = @_; return factorial($c + $w) / (factorial($c) * factorial($w)); } sub factorial { my ($n) = @_; my $f = 1; $f *= $_ for 2 .. $n; return $f; } #### 0:30 >perl 760_SoPW.pl | 1| 2| 3| 4| 5| 6| 7| 8| 9| --+--+--+---+----+----+----+-----+-----+-----+ 1| 2| 3| 4| 5| 6| 7| 8| 9| 10| 2| 3| 6| 10| 15| 21| 28| 36| 45| 55| 3| 4|10| 20| 35| 56| 84| 120| 165| 220| 4| 5|15| 35| 70| 126| 210| 330| 495| 715| 5| 6|21| 56| 126| 252| 462| 792| 1287| 2002| 6| 7|28| 84| 210| 462| 924| 1716| 3003| 5005| 7| 8|36|120| 330| 792|1716| 3432| 6435|11440| 8| 9|45|165| 495|1287|3003| 6435|12870|24310| 9|10|55|220| 715|2002|5005|11440|24310|48620| 10|11|66|286|1001|3003|8008|19448|43758|92378| 0:30 >