permutation with repetition

A

artem

hi all,

i am trying to write a program that will give me all permutations of
the given set, with repetition.
ex:
set: {A,B,C} length: 3 (the user enters the set and the length)
AAA
AAB
AAC
ABA
......
ABC

i understand the algorithem, but still cant write it. could someone
give me the source for this or help me to write it.

thank you
 
V

voorth

hi all,

i am trying to write a program that will give me all permutations of
the given set, with repetition.
ex:
set: {A,B,C} length: 3 (the user enters the set and the length)
AAA
AAB
AAC
ABA
.....
ABC

i understand the algorithem, but still cant write it. could someone
give me the source for this or help me to write it.

thank you

Just a hint: nested for loops.

oh, and are you aware that what you want as output is not a
permutation?

-- Henk van Voorthuijsen
 
O

Oliver Wong

artem said:
hi all,

i am trying to write a program that will give me all permutations of
the given set, with repetition.
ex:
set: {A,B,C} length: 3 (the user enters the set and the length)
AAA
AAB
AAC
ABA
.....
ABC

i understand the algorithem, but still cant write it. could someone
give me the source for this or help me to write it.

What's the algorithm?

- Oliver
 
K

Ken

i understand the algorithem, but still cant write it. could someone
What's the algorithm?

- Oliver

Oh thats quite simple...

1) Find a news group
2) Ask for group to do your homework
3) Read results
4) If results are not adequate branch to 1
 
S

sohaninfo

hi all,

i am trying to write a program that will give me all permutations of
the given set, with repetition.
ex:
set: {A,B,C} length: 3 (the user enters the set and the length)
AAA
AAB
AAC
ABA
.....
ABC

i understand the algorithem, but still cant write it. could someone
give me the source for this or help me to write it.

thank you

import ncst.pgdst.*;

public class permutation{
public static void main(String[] agrs)throws Exception
{
SimpleInput si=new SimpleInput();
Perm pm=new Perm();
pm.permute(0);


}
}

class Perm{
int n,r=3,count,size=3,RHS;
char charList[]=new char[26];
char chrs[]={'a','b','c'};
char arr[]={'a','b','c'};
void swap(char []a, int i, int j)
{
char temp;
temp=a;
a=a[j];
a[j]=temp;

}
void permute(int start)
{
int i,j;
if(start==r)
{

{
for(i=0;i<r;i++)
System.out.print(charList);
System.out.println();
}
}
else
{
i=start;
int k=0;
for(j=0;j<3;j++)
{
charList=chrs[k++];
permute(start+1);
}


}
}
void permute2(int i)
{
int j=0,k=0;
char temp;
if(i == size)
{
return;
}
for(j = i; j < size; j++)
{

swap(arr,i,j);
permute2(i+1);
if(i == size - 1)
{
System.out.print("Permute["+count+"]=");
// for(k = 0;k< size;k++)
System.out.print(arr);
System.out.println();
swap(arr,j,i);
}

temp = arr;
arr = arr[j];
arr[j] = temp;
}
}
}
 
H

Hendrik Maryns

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

(e-mail address removed) schreef:
import ncst.pgdst.*;

public class permutation{

<snip a solution> Tsk, tsk.

First of all: http://mindprod.com/jgloss/homework.html

But then, you could have done some searching:
http://mindprod.com/jgloss/permutation.html

H.
- --
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)

iD8DBQFGAWONe+7xMGD3itQRAnScAJ9aITpPVUPCNFbGzMNvwMT/tIlmggCcCxtv
8IOVdkdyaEtI36tkI8ynD4Y=
=+VEK
-----END PGP SIGNATURE-----
 

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,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top