Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Permuting using any number of given chars

Reply
Thread Tools

Permuting using any number of given chars

 
 
Brian Wakem
Guest
Posts: n/a
 
      05-17-2005
I can use Algorithm:ermute to output all permutations of 1 2 3

123
132
312
213
231
321


But what I'm looking for is all possible permutations using any number of
the input chars.

Like this -

1
2
3
12
13
21
23
31
32
123
132
312
213
231
321


I can't think of a way right now and I can't find a module that does it.
Any ideas?



--
Brian Wakem

 
Reply With Quote
 
 
 
 
Anno Siegel
Guest
Posts: n/a
 
      05-17-2005
Brian Wakem <> wrote in comp.lang.perl.misc:
> I can use Algorithm:ermute to output all permutations of 1 2 3
>
> 123
> 132
> 312
> 213
> 231
> 321
>
>
> But what I'm looking for is all possible permutations using any number of
> the input chars.
>
> Like this -
>
> 1
> 2
> 3
> 12
> 13
> 21
> 23
> 31
> 32
> 123
> 132
> 312
> 213
> 231
> 321
>
>
> I can't think of a way right now and I can't find a module that does it.


Split the problem. You know how to get all permutations for a given
set. So find all subsets of the input characters ('', '3', '2', '23', '1',
'13', '12', '123') and apply your solution to each.

for ( subsets( '123') ) {
print_permutations( $_);
}

The definition of subsets() is left as an exercise in recursion.

Anno
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to truncate char string fromt beginning and replace chars instring by other chars in C or C++? Hongyu C++ 9 08-08-2008 12:18 PM
permuting over nested dicts? Christian Meesters Python 8 11-08-2007 12:37 PM
Floats to chars and chars to floats Kosio C Programming 44 09-23-2005 09:49 AM
permuting letters and fairy tales Johannes Nix Python 19 11-17-2004 10:47 PM
receiving ??? chars instead of "special" chars M.Posseth ASP .Net Web Services 3 11-16-2004 07:00 PM



Advertisments