<?xml version="1.0" encoding="windows-1252"?>
<node id="991276" title="Is it possible to generate all possible combinations of 2-letter and 3-letter words in perl?" created="2012-09-02 10:11:37" updated="2012-09-02 10:11:37">
<type id="115">
perlquestion</type>
<author id="942579">
supriyoch_2008</author>
<data>
<field name="doctext">
&lt;p&gt;Hi Perl Monks,&lt;/p&gt;
&lt;p&gt; I am a beginner in perl programming. I am 
interested in generating all possible combinations of 2-letter &amp; 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?&lt;/p&gt;

&lt;code&gt;#!/usr/bin/perl
use warnings;
use strict;
## Perl script to create all possible combinations of A,T,G &amp; C 
# of varying lengths:
print"\n This program will generate all possible combinations of A,T,G &amp; C:";
print"\n Enter the length of words you want (say 2 or 3 etc.): ";
 my $num=&lt;STDIN&gt;;my $four=4;
 chomp $num;
 my $no_combi=$four**$num;
 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";
exit;&lt;/code&gt;

&lt;p&gt;The expected results will look like:&lt;/p&gt;
&lt;code&gt;All possible combinations of 2-letter words (16):
AA
AT
AG
AC
TA
TT
TG
TC
GA
GT
GG
GC
CA
CT
CG
CC&lt;/CODE&gt;
&lt;p&gt;For 3-letter words, there will be 64 combinations like:&lt;/p&gt;
&lt;CODE&gt;All possible combinations of 3-letter words:
AAA
...
...
...
CCC&lt;/code&gt;</field>
</data>
</node>
