Combinations Help

Discussion in 'Java' started by billygotmail@googlemail.com, Feb 19, 2007.

  1. Guest

    Hey,

    Does anyone have any idea how I could find all possible n-combinations
    of an array {1,2,3,4,5,6,7,8,9} (where 1≤n≤9), add up these
    combinations and output them in an array?

    I realise this array would be pretty big, and I'm not sure if the
    average PC would be able to handle it. What do you think? I've tried
    Googling for examples, to no avail.

    Thanks.
    , Feb 19, 2007
    #1
    1. Advertising

  2. wrote:
    > Hey,
    >
    > Does anyone have any idea how I could find all possible n-combinations
    > of an array {1,2,3,4,5,6,7,8,9} (where 1≤n≤9), add up these
    > combinations and output them in an array?
    >
    > I realise this array would be pretty big, and I'm not sure if the
    > average PC would be able to handle it. What do you think? I've tried
    > Googling for examples, to no avail.


    If order within a combination does not matter, a PC should handle it
    fine. The numbers of combinations are the coefficients from the tenth
    row of Pascal's triangle, 1, 9, 36, 84, 126, 126, 84, 36, 9, 1.

    My favorite approach to this type of question is to separate the
    algorithm thinking from the coding.

    Completely ignoring programming, work out how you would do small cases,
    with a paper and pencil. Begin with 2 numbers, and gradually work up
    until you feel you know how to do it in general.

    After you know how to do the problem yourself, try to translate that
    into loops and arrays.

    Patricia
    Patricia Shanahan, Feb 19, 2007
    #2
    1. Advertising

  3. writes:

    > Does anyone have any idea how I could find all possible
    > n-combinations of an array {1,2,3,4,5,6,7,8,9} (where 1≤n≤9),
    > add up these combinations and output them in an array?


    There are two kinds of n-combinations of {1,2,3,4}: the
    n-combinations of {2,3,4}, and the (n - 1)-combinations of
    {2,3,4} with 1 added.
    Jussi Piitulainen, Feb 20, 2007
    #3
  4. Guest

    Thank you both for your help. I think I've got it working.

    Cheers, Mike.
    , Mar 15, 2007
    #4
    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. Lily
    Replies:
    16
    Views:
    1,327
    Bob Jenkins
    May 10, 2004
  2. GrantMagic

    Breaking URL character combinations

    GrantMagic, Oct 22, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    419
    bruce barker
    Oct 22, 2004
  3. Roedy Green

    Re: combinations

    Roedy Green, Jul 30, 2003, in forum: Java
    Replies:
    0
    Views:
    395
    Roedy Green
    Jul 30, 2003
  4. Alex S.

    Re: combinations

    Alex S., Aug 4, 2003, in forum: Java
    Replies:
    0
    Views:
    394
    Alex S.
    Aug 4, 2003
  5. Alexander Antonakakis

    Help on algorithm to calculate combinations

    Alexander Antonakakis, Feb 25, 2010, in forum: Ruby
    Replies:
    8
    Views:
    144
    Josh Cheek
    Feb 25, 2010
Loading...

Share This Page