Velocity Reviews > Java > permutation with repetition

# permutation with repetition

artem
Guest
Posts: n/a

 02-23-2007
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

voorth
Guest
Posts: n/a

 02-23-2007
On Feb 23, 5:19 am, "artem" <(E-Mail Removed)> wrote:
> 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

Oliver Wong
Guest
Posts: n/a

 02-23-2007

"artem" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> 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

Ken
Guest
Posts: n/a

 02-24-2007
> > 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

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

sohaninfo@gmail.com
Guest
Posts: n/a

 03-21-2007
On Feb 23, 9:19 am, "artem" <(E-Mail Removed)> wrote:
> 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[i];
a[i]=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[i]);
System.out.println();
}
}
else
{
i=start;
int k=0;
for(j=0;j<3;j++)
{
charList[i]=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[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}

Hendrik Maryns
Guest
Posts: n/a

 03-21-2007
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

http://www.velocityreviews.com/forums/(E-Mail Removed) schreef:
> On Feb 23, 9:19 am, "artem" <(E-Mail Removed)> wrote:
>> 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{

<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+7xMGD3itQRAnScAJ9aITpPVUPCNFbGzMNvwM T/tIlmggCcCxtv
8IOVdkdyaEtI36tkI8ynD4Y=
=+VEK
-----END PGP SIGNATURE-----

Lew
Guest
Posts: n/a

 03-21-2007
Hendrik Maryns wrote:
> <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

It's been about four weeks. The homework had to have been due before now. It
should be safe to post a solution.

Maybe next semester's crowd will search Usenet for the answer and plagiarize
it then.

-- Lew

 Thread Tools

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post daniel_nordlund_1982@hotmail.com Java 5 11-18-2006 10:15 AM Mike Computer Support 3 08-06-2003 11:54 AM anthonyberet Computer Support 1 08-06-2003 12:57 AM trout Computer Support 0 08-05-2003 10:09 PM philo Computer Support 0 08-05-2003 09:56 PM

Advertisments