Hi PerlMonks,

It might be a silly question. But I donot find a simple perl code to solve this problem. I have an array like @a=qw/A B C D/; and I'm interested to get all possible permutations of say 3 elements out of 4 in the array and their total numbers i.e. 4p3=4!/(4-3)!=24 permutations along with 4 other uniform permutations (i.e. AAA,BBB, CCC,DDD). Thus total number of permutations will be 24+4=28. I need the permutations like ABC,ABD,BCD .. DDD and their total numbers (28). I have gone through some posts but nowhere I find the answer to this type of basic question. May I request the Perlmonks to provide suggestions for this problem? I am sure that I have put a very silly question. Moreover, the code must work for permutations of 2 or 4 elements out of 4 i.e. 4p2 and 4p4 along with their uniform permutations with little change in the code.


In reply to How can one generate all possible permutations of r elements out of n where r<n? 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!
  • 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:
    & &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.