Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2007

Tip: Looking for answers? Try searching our database.

permutation with repetition

Thread view: 
artem - 23 Feb 2007 04:19 GMT
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 - 23 Feb 2007 09:51 GMT
> hi all,
>
[quoted text clipped - 13 lines]
>
> 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 - 23 Feb 2007 21:17 GMT
> hi all,
>
[quoted text clipped - 11 lines]
> 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 - 24 Feb 2007 18:16 GMT
> > 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 - 21 Mar 2007 15:31 GMT
> hi all,
>
[quoted text clipped - 13 lines]
>
> 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 - 21 Mar 2007 17:55 GMT
sohaninfo@gmail.com schreef:
>> hi all,
>>
[quoted text clipped - 17 lines]
>
> 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
Lew - 21 Mar 2007 20:17 GMT
> <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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.