The Perl built in glob function can do permutations. Here are some examples:
In a permutation, order matters, in a combination, order doesn't matter.
#!/usr/bin/perl
use strict;
use warnings;
my @permutations = glob "{1,2,3}" x 3;
print "@permutations\n";
@permutations = glob "{1,1,7}" x 3;
print "@permutations\n";
@permutations = glob "{a,b,c}{1,2}";
print "@permutations\n";
__END__
extra new lines added for readability
Example1:
111 112 113 121 122 123 131 132 133
211 212 213 221 222 223 231 232 233
311 312 313 321 322 323 331 332 333
Example2:
111 111 117 111 111 117 171 171 177
111 111 117 111 111 117 171 171 177
711 711 717 711 711 717 771 771 777
Example:3 combinations "one from column A", one from column "B".
a1 a2 b1 b2 c1 c2
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.