If your input sets get much bigger than about 18 elements, you will probably want to consider converting this to an iterator form:
#! perl -slw
use strict;
sub parts {
my $n = shift;
return [] unless @_;
map {
local @_ = @_;
my $first = join '', splice @_, 0, $_;
map {
[ $first, @$_ ]
} parts( $n, @_ );
} 1 .. ( @_ < $n ? @_ : $n );
}
print join'|', @$_ for parts( 3, 'a'..'g' );
__DATA__
C:\test>982945.pl
a|b|c|d|e|f|g
a|b|c|d|e|fg
a|b|c|d|ef|g
a|b|c|d|efg
a|b|c|de|f|g
a|b|c|de|fg
a|b|c|def|g
a|b|cd|e|f|g
a|b|cd|e|fg
a|b|cd|ef|g
a|b|cd|efg
a|b|cde|f|g
a|b|cde|fg
a|bc|d|e|f|g
a|bc|d|e|fg
a|bc|d|ef|g
a|bc|d|efg
a|bc|de|f|g
a|bc|de|fg
a|bc|def|g
a|bcd|e|f|g
a|bcd|e|fg
a|bcd|ef|g
a|bcd|efg
ab|c|d|e|f|g
ab|c|d|e|fg
ab|c|d|ef|g
ab|c|d|efg
ab|c|de|f|g
ab|c|de|fg
ab|c|def|g
ab|cd|e|f|g
ab|cd|e|fg
ab|cd|ef|g
ab|cd|efg
ab|cde|f|g
ab|cde|fg
abc|d|e|f|g
abc|d|e|fg
abc|d|ef|g
abc|d|efg
abc|de|f|g
abc|de|fg
abc|def|g
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.