Creating a permutation list

M

markredd

Hello world,
I'm looking for an algorithm in order to perform this operation: I
have a set of N possible values and I want to generate all the
possibile permutations composed by M slots without repetitions and not
considering the order.

Note: I don't know what are the values of N and M befor the software
starts, so i have to implement it at run-time.

For example, if N=4 with values {1 , 2 , 3 , 4} and M=3, I will obtain
only 4 combinations, for example:
(1,2,3) [or (3,2,1), or (2,1,3), the order doesn't matter]
(1,3,4)
(1,2,4)
(2,3,4)

Can you describe an algorithm? (I don't need code, I hope I will able
to develop it!)
thanks
 
B

Ben Bacarisse

markredd said:
Hello world,
I'm looking for an algorithm in order to perform this operation: I
have a set of N possible values and I want to generate all the
possibile permutations composed by M slots without repetitions and not
considering the order.

Note: I don't know what are the values of N and M befor the software
starts, so i have to implement it at run-time.

For example, if N=4 with values {1 , 2 , 3 , 4} and M=3, I will obtain
only 4 combinations, for example:
(1,2,3) [or (3,2,1), or (2,1,3), the order doesn't matter]
(1,3,4)
(1,2,4)
(2,3,4)

Can you describe an algorithm? (I don't need code, I hope I will able
to develop it!)

Then your question is not really a C one. comp.programming is a good
group for algorithm questions. Also, you my want to see if you can
persuade people that this is not your homework. It certainly looks
like it!
 
S

Stefan Ram

markredd said:
Can you describe an algorithm? (I don't need code, I hope I will able
to develop it!)

#include <stdio.h>

int main( void )
{ int const t = 3;
int const name[] ={ 1, 2, 3, 4 };

int const n = sizeof name / sizeof 0[ name ];
int j;
int c[ t + 3 ];
for( j = 1; j <= t; ++j )c[ j ]= j - 1;
c[ t + 1 ]= n;
c[ t + 2 ]= 0;
outer:
goto print;
inner:
for( j = 1; c[ j ]+ 1 == c[ j + 1 ]; ++j )c[ j ]= j - 1;
if( j > t )goto end;
c[ j ]= c[ j ]+ 1;
goto outer;
print:
for( int i = 1; i <= t; ++i )
printf( "%d ", name[ c[ i ]]);
printf( "\n" );
goto inner;
end: ; }
 
U

user923005

Hello world,
I'm looking for an algorithm in order to perform this operation: I
have a set of N possible values and I want to generate all the
possibile permutations composed by M slots without repetitions and not
considering the order.

Note: I don't know what are the values of N and M befor the software
starts, so i have to implement it at run-time.

For example, if N=4 with values {1 , 2 , 3 , 4} and M=3, I will obtain
only 4 combinations, for example:
(1,2,3) [or (3,2,1), or (2,1,3), the order doesn't matter]
(1,3,4)
(1,2,4)
(2,3,4)

Can you describe an algorithm? (I don't need code, I hope I will able
to develop it!)
thanks

Go here:
http://www.jjj.de/fxt/fxtpage.html#fxtbook

Click on the book "Matters Computational"
P.S.
Jörg Arndt is a really nice guy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top