Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: all permutations of given lenght

by Corion (Patriarch)
on Aug 11, 2020 at 07:24 UTC ( [id://11120595]=note: print w/replies, xml ) Need Help??


in reply to all permutations of given lenght

Maybe you want Algorithm::Loops::NextPermute ? You can give it lists of lists of characters and it will spit out strings (well, lists) of the combinations:

my @characters = (qw(C N N N N N )); my @list= sort ; do { usePermutation( @list ); } while( NextPermute( @list ) );

... or maybe the NestedLoops function is more it - I'm not sure if you also want to generate strings with 2C 4N and so on, and what other characters come into play.

If there are only two characters coming into play, generating all permutations is equivalent to counting from 1..2**$number_of_characters_in_target_string and interpreting that number as binary, a 1 is "use that character" and a 0 means "use the other character".

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11120595]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-19 04:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found