Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Combinations Help

Reply
Thread Tools

Combinations Help

 
 
billygotmail@googlemail.com
Guest
Posts: n/a
 
      02-19-2007
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.

 
Reply With Quote
 
 
 
 
Patricia Shanahan
Guest
Posts: n/a
 
      02-19-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) 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
 
Reply With Quote
 
 
 
 
Jussi Piitulainen
Guest
Posts: n/a
 
      02-20-2007
(E-Mail Removed) 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.
 
Reply With Quote
 
billygotmail@googlemail.com
Guest
Posts: n/a
 
      03-15-2007
Thank you both for your help. I think I've got it working.

Cheers, Mike.

 
Reply With Quote
 
 
 
Reply

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 Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help on algorithm to calculate combinations Alexander Antonakakis Ruby 8 02-25-2010 06:19 PM
MS - exam combinations... Corey B. MCSE 12 06-25-2004 08:54 PM
millions combinations of test vectors for ALU Lily VHDL 16 05-10-2004 07:22 PM
Re: 70-292 Combinations Tom Helms [MSFT] MCSE 1 02-29-2004 01:44 PM
MCSE 2000 exam combinations TheXman MCSE 1 12-05-2003 01:27 PM



Advertisments