If you're really bored, you might try to resolve the table at the end -- characters down; wildcards across -- to a formula.

For c characters and w wildcards, the number of different combinations is (c + w)! / c! w!:

#! 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 .. WILDCARD +S; } 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; }

Output:

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 >

Conclusion: apparently I was really bored. :-)

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


In reply to Re^4: combinations of given string by Athanasius
in thread combinations of given string by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.