Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

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?

#!/usr/bin/perl use warnings; use strict; ## 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; 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;

The expected results will look like:

All possible combinations of 2-letter words (16): AA AT AG AC TA TT TG TC GA GT GG GC CA CT CG CC

For 3-letter words, there will be 64 combinations like:

All possible combinations of 3-letter words: AAA ... ... ... CCC

In reply to Is it possible to generate all possible combinations of 2-letter and 3-letter words in perl? by supriyoch_2008

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!
  • 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, 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
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (13)
    As of 2014-09-02 12:13 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite cookbook is:










      Results (22 votes), past polls