Re: how to print all the combinations ??
- From: "Barry" <barryg@xxxxxxxxxxxxxxxxxx>
- Date: Tue, 28 Mar 2006 07:02:27 -0600
"Rob Thorpe" <robert.thorpe@xxxxxxxxxxxx> wrote in message
news:1143535101.568487.38860@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Mark P wrote:
Maciej Pilichowski wrote:
On 27 Mar 2006 22:29:20 -0800, "sudharsan" <suderson.tk@xxxxxxxxx>
wrote:
for a given set of numbers how to print all sort of combinations
for example if a[]={1,2,3};
need to print :- 123,132,213,231,312,321
So you need to print all the _permutations_. Now, when you know what
you are looking for use google.
Some languages can do this very easily, for example, C++ has the
standard library function next_permutation. Otherwise you'll need to
develop an equivalent function on your own.
It isn't that hard. You just need to run 3 loops, each checking that
the value used is a perm.
Ie. generate
111
112
113
121
122
123
131
132
and pick 123, 132 etc by preventing each nested loop from using digits
already used by those it is enclosed by.
next_permutation is of-course useful though.
Yes if you limit the number to 3, but I don't think that was the OPs intent.
Adding another loop for each number isn't reasonable even for fairly small
numbers. Plus, although the example should the set being consecutive
integers, I would not assume this was a requirement.
.
- References:
- how to print all the combinations ??
- From: sudharsan
- Re: how to print all the combinations ??
- From: Maciej Pilichowski
- Re: how to print all the combinations ??
- From: Mark P
- Re: how to print all the combinations ??
- From: Rob Thorpe
- how to print all the combinations ??
- Prev by Date: Re: String concatenation design
- Next by Date: Re: String concatenation design
- Previous by thread: Re: how to print all the combinations ??
- Next by thread: Re: how to print all the combinations ??
- Index(es):
Relevant Pages
|