I want to produce from a give string all permutations of its
characters.
Building all permutations of something is a typical recursive task.
But in this case I dont want a recursive solution because:
1.) Each call of the according method should return only one
permutation of all possible permutations.
and
2.) Since the count of permutation rapidly grows with the count of
characters to permute I dont want to calculate all permutations
first and store them in a big BIG array.
Each new call that method should calculate just that next new
permutation.
I must confess: I have thought about that and did not find any
solution. Even the Sedgwick only offers a recursive solution.
There is a solution in the pleac cookbook, I have transferred it from the perl cookbook.
See Arrays
Search for "program permute"
The second solution enables you to get the n-th permutation, so you can just increment a
integer each time you call the method, and you don't need to store any arrays.
Regards
Karsten Meier
Meino Christian Cramer wrote:
···
Hi,
I want to produce from a give string all permutations of its
characters.
Building all permutations of something is a typical recursive task.
But in this case I dont want a recursive solution because:
1.) Each call of the according method should return only one
permutation of all possible permutations.
and
2.) Since the count of permutation rapidly grows with the count of
characters to permute I dont want to calculate all permutations
first and store them in a big BIG array.
Each new call that method should calculate just that next new
permutation.
I must confess: I have thought about that and did not find any
solution. Even the Sedgwick only offers a recursive solution.
Just for clarity.. my solution is recursive, but it doesn't have the 2
problems you mentioned.
Ruben
···
At Sat, 17 Jul 2004 00:14:00 +0900, Ruben wrote:
At Fri, 16 Jul 2004 20:36:27 +0900, > Meino Christian Cramer wrote:
>
> I want to produce from a give string all permutations of its
> characters.
>
> Building all permutations of something is a typical recursive task.
> But in this case I dont want a recursive solution because:
Seemed like a nice little challenge... so this is what i came up with.