Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Answer: How would I be able to find all possible letter arrangements?

by arhuman (Vicar)
on Nov 02, 2001 at 19:46 UTC ( #122813=categorized answer: print w/replies, xml ) Need Help??

Q&A > strings > How would I be able to find all possible letter arrangements? - Answer contributed by arhuman

Directly from perlfaq4 :

Here's a little program that generates all
permutations of all the words on each line of
input. The algorithm embodied in the permute()
function should work on any list:
#!/usr/bin/perl -n # tsc-permute: permute each word of input permute([split], []); sub permute { my @items = @{ $_[0] }; my @perms = @{ $_[1] }; unless (@items) { print "@perms\n"; } else { my(@newitems,@newperms,$i); foreach $i (0 .. $#items) { @newitems = @items; @newperms = @perms; unshift(@newperms, splice(@newitems, $i, 1)); permute([@newitems], [@newperms]); }

  • Comment on Answer: How would I be able to find all possible letter arrangements?
  • Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
[Discipulus]: Eily adjust the shot: i'll be at seaside when it will happen
[Eily]: oh, I'll have to find something else then, don't want to litter the sea. Fireworks maybe?
Eily time to eat
[Discipulus]: good la?unch

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2017-07-27 10:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (409 votes). Check out past polls.