473,511 Members | 14,393 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

to print permutations...

Suppose we are having 3 variables...a,b,c
And we want to print the permutations of these variables...Such
as...abc,acb,bca...all 6 of them...
But we are not supposed to do it mannually...

I want to know that formula by which this can be possible...

Then that program will be ok for nnumber of variables....
Can anyone help me for that?

May 26 '07 #1
5 2678
"Shraddha" wrote:
Suppose we are having 3 variables...a,b,c
And we want to print the permutations of these variables...Such
as...abc,acb,bca...all 6 of them...
But we are not supposed to do it mannually...

I want to know that formula by which this can be possible...

Then that program will be ok for nnumber of variables....
Can anyone help me for that?
This might help

http://en.wikipedia.org/wiki/Permuta...s_in_computing

It seems to have some "Pascalish" looking source code.

Because of the difficulties of handling templates, I would expect the source
code used by next_permutation ( or whatever) is in the \include\ directory
of your compiler. I never actually looked, though.
May 26 '07 #2
On 5 26 , 9 13 , Shraddha <shraddhajosh...@gmail.comwrote:
Suppose we are having 3 variables...a,b,c
And we want to print the permutations of these variables...Such
as...abc,acb,bca...all 6 of them...
But we are not supposed to do it mannually...

I want to know that formula by which this can be possible...

Then that program will be ok for nnumber of variables....
Can anyone help me for that?
I think it's a algorithm problem. You should study the combination
mathematics. There is the algorithm for generating permutations in
this course.

May 26 '07 #3
"osmium" writes:
"Shraddha" wrote:
>Suppose we are having 3 variables...a,b,c
And we want to print the permutations of these variables...Such
as...abc,acb,bca...all 6 of them...
But we are not supposed to do it mannually...

I want to know that formula by which this can be possible...

Then that program will be ok for nnumber of variables....
Can anyone help me for that?

This might help

http://en.wikipedia.org/wiki/Permuta...s_in_computing

It seems to have some "Pascalish" looking source code.

Because of the difficulties of handling templates, I would expect the
source code used by next_permutation ( or whatever) is in the \include\
directory of your compiler. I never actually looked, though.
The OP is flitting around amongst newsgroups, thus the C++ answer in a C
newsgroup. Sorry. The answer is formed with respect to a question and
answer the OP got a few days ago.
May 26 '07 #4
Shraddha wrote:
Suppose we are having 3 variables...a,b,c
And we want to print the permutations of these variables...Such
as...abc,acb,bca...all 6 of them...
But we are not supposed to do it mannually...

I want to know that formula by which this can be possible...

Then that program will be ok for nnumber of variables....
Can anyone help me for that?
Imagine that you had a function that would print
all the permutations of an array of N variables. Can
you think of a way to use that function to print all
the permutations of an array of N+1 variables?

Second question: Suppose N is equal to one. Can
you think of a way to print all the permutations of
a one-element array? If so, then by using the recipe
from the first paragraph you can find a method that
prints all the permutations of a two-element array.
Applying the recipe to that method gives you a way to
handle three-element arrays, then four, then five, ...

A convenient way to express this in C is to turn
the problem around. The recipe tells you how to permute
N elements if only you had a method for permuting N-1,
which you could do if you had a method for N-2, and so
on. Eventually you get down to "If only I had a method
for permuting one element," which you'll need to solve
on your own.

If that's not enough of a hint, you haven't been
paying enough attention in class. Ask your teacher for
remedial help.

--
Eric sosman
es*****@acm-dot-org.invalid
May 26 '07 #5

"Shraddha" <sh*************@gmail.comwrote in message
news:11*********************@z28g2000prd.googlegro ups.com...
Suppose we are having 3 variables...a,b,c
And we want to print the permutations of these variables...Such
as...abc,acb,bca...all 6 of them...
But we are not supposed to do it mannually...

I want to know that formula by which this can be possible...

Then that program will be ok for nnumber of variables....
Can anyone help me for that?
You've got N! permutations of a string.
So the manual approach breaks down at about 6, the computer approach at
something like N=15.

As the said, Eric Sosman bascially you need to take each element in turn,
then permute the remainder.

So code looks something like this

/*
give user a nice wrapper, permute a string to an output
*/
void permute(char *str, FILE *fpout)
{
char buff[20]; /* you will never need more than 20 characters unless you
have a really super duper computer */
/* start with an empty prefix */
strcpy(buff, "");
permuter(buff, str, fpout);
}

/*
real function is recursive. We print a prefix
*/
static void permuter(char *prefix, char *str, FILE *fp)
{
/* check for strings of length 1, print them (with prefix), and terminate
*/

/* take each element of the string, add it to the prefix, then
call permuter() on the remaining elements */
}
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

May 26 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
5652
by: Steve Goldman | last post by:
Hi, I am trying to come up with a way to develop all n-length permutations of a given list of values. The short function below seems to work, but I can't help thinking there's a better way. ...
20
2257
by: John Trunek | last post by:
I have a set of X items, but want permutations of length Y (X > Y). I am aware of the permutation functions in <algorithm>, but I don't believe this will do what I want. Is there a way, either...
20
41266
by: anurag | last post by:
hey can anyone help me in writing a code in c (function) that prints all permutations of a string.please help
1
10907
by: JosAH | last post by:
Greetings, last week we talked a bit about generating permutations and I told you that this week will be about combinations. Not true; there's a bit more to tell about permutations and that's...
5
1754
by: Shraddha | last post by:
If we have three variables a,b,c...which are char variables....then hoe to print there all permutations? for example....abc, bac, cab.......all of them....
82
3580
by: Bill Cunningham | last post by:
I don't know if I'll need pointers for this or not. I wants numbers 10^16. Like a credit card 16 digits of possible 10 numbers, so I guess that would be 10^16. So I have int num ; These are of...
0
7251
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7148
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7367
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5072
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3217
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
790
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.