Re: how to print all the combinations ??
- From: "Rob Thorpe" <robert.thorpe@xxxxxxxxxxxx>
- Date: 28 Mar 2006 00:38:21 -0800
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.
.
- Follow-Ups:
- Re: how to print all the combinations ??
- From: Barry
- Re: how to print all the combinations ??
- 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
- how to print all the combinations ??
- Prev by Date: Re: how to print all the combinations ??
- Next by Date: Re: Misuse of for
- Previous by thread: Re: how to print all the combinations ??
- Next by thread: Re: how to print all the combinations ??
- Index(es):