permutation with repetition

Discussion in 'Java' started by artem, Feb 23, 2007.

  1. artem

    artem Guest

    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
    artem, Feb 23, 2007
    #1
    1. Advertising

  2. artem

    voorth Guest

    On Feb 23, 5:19 am, "artem" <> 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
    voorth, Feb 23, 2007
    #2
    1. Advertising

  3. artem

    Oliver Wong Guest

    "artem" <> wrote in message
    news:...
    > 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
    Oliver Wong, Feb 23, 2007
    #3
  4. artem

    Ken Guest

    > > 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
    Ken, Feb 24, 2007
    #4
  5. artem

    Guest

    On Feb 23, 9:19 am, "artem" <> 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;
    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;
    }
    }
    }
    , Mar 21, 2007
    #5
  6. -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    schreef:
    > On Feb 23, 9:19 am, "artem" <> 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+7xMGD3itQRAnScAJ9aITpPVUPCNFbGzMNvwMT/tIlmggCcCxtv
    8IOVdkdyaEtI36tkI8ynD4Y=
    =+VEK
    -----END PGP SIGNATURE-----
    Hendrik Maryns, Mar 21, 2007
    #6
  7. artem

    Lew Guest

    Lew, Mar 21, 2007
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    5
    Views:
    351
  2. bullockbefriending bard

    Generator for k-permutations without repetition

    bullockbefriending bard, Jul 4, 2007, in forum: Python
    Replies:
    4
    Views:
    1,029
    =?ISO-8859-1?Q?Nis_J=F8rgensen?=
    Jul 4, 2007
  3. Jhovarie
    Replies:
    0
    Views:
    429
    Jhovarie
    Jan 13, 2011
  4. Giles Bowkett

    still more relentless non-repetition

    Giles Bowkett, Oct 31, 2006, in forum: Ruby
    Replies:
    13
    Views:
    177
    David Vallner
    Nov 2, 2006
  5. Shawn W_
    Replies:
    2
    Views:
    170
    Peter Szinek
    Jan 26, 2007
Loading...

Share This Page