Hi Perl Monks,
I am a beginner in perl programming. I am
interested in generating all possible combinations of 2-letter & 3-letter words
from a set of four letters (A,T,G,C), choosing one letter at a time for each position.
I searched for perl scripts in CPAN and other online sources but I didn't get the codes.
But a few scripts are indeed available for permutations and combinations. If the size of
the word is small, it's easy to do it manually but when the size of the word is 10 or
more it is time-consuming to generate all the combinations. If any perl code is available,
it will be very useful to the biologists. If 'n' is the size of the word, then 4**n (i.e. 4 to the power word size) combinations
are possible unlike possible permutations and combinations. For 2-letter words, there will be 16 combinations as given below (unlike 12
permutations and 6 combinations) and for 3-letter words 64 combinations are possible in the same
way (unlike fewer permutations and combinations). May I request perl monks to suggest me
some reference reading material or codes for this purpose?
## Perl script to create all possible combinations of A,T,G & C
# of varying lengths:
print"\n This program will generate all possible combinations of A,T,G
+ & C:";
print"\n Enter the length of words you want (say 2 or 3 etc.): ";
my $num=<STDIN>;my $four=4;
print"\n Total Number of Combinations= $no_combi\n";
my $combi_2l=". . .????";
my $combi_3l=". . .????";
print"\n All possible combinations of 2-letter words: ???$combi_2l\n";
print"\n All possible combinations of 3-letter words: ???$combi_3l\n";
The expected results will look like:
All possible combinations of 2-letter words (16):
For 3-letter words, there will be 64 combinations like:
All possible combinations of 3-letter words:
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
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:
Outside of code tags, you may need to use entities for some characters:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||