Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: All possible combinations of a 1D array

  1. #1
    Junior Member
    Join Date
    Aug 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default All possible combinations of a 1D array

    Hi everyone, I'm Gabriel from Greece,

    I have a little problem with a part of code I'm trying to write. Actually it's a part from a bigger code.
    I want to do this:

    Lets say that I have a String array: projects{"A", "B", "C", ...}. The size of the array can be changed so the code should worn for n elements.

    I want this output:

    A
    B
    C
    AB
    AC
    BC
    ABC
    ...

    Note that AB is equal to BA, AC=CA, ...

    Thanks for your time for reading this and I would really appreciate if someone could write me the code, because I'm trying to write it for a few days now and I couldn't do anything. Thanks again.


  2. #2
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: All possible combinations of a 1D array

    wikipedia combinations, get an idea of the maths behind it. Then limit the size of the array to one chunk then 2 chunks etc etc

    Chris

  3. #3
    Junior Member
    Join Date
    Aug 2009
    Location
    San Fransisco
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: All possible combinations of a 1D array

    Combination Generator
    See, I am not big fan of copying especially programming. You copy everything, fail in everything, but be loyal with programming and you will rock. The above should be some code, which I suggest you take a look, once you spend some time yourself. Also your problem is little bit more than generating combinations. (basically combinations - palindromes)

    Acumen
    Lucid forums