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.

Combinations Help

Thread view: 
billygotmail@googlemail.com - 19 Feb 2007 19:45 GMT
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.
Patricia Shanahan - 19 Feb 2007 20:04 GMT
> Hey,
>
[quoted text clipped - 5 lines]
> 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
Jussi Piitulainen - 20 Feb 2007 08:49 GMT
> 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.
billygotmail@googlemail.com - 15 Mar 2007 15:48 GMT
Thank you both for your help. I think I've got it working.

Cheers, Mike.


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



©2008 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.