Welcome to the most active Linux Forum on the web.
 Home Forums HCL Reviews Tutorials Articles Register Search Today's Posts Mark Forums Read
 LinuxQuestions.org Generating Combinations of Objects
 Programming This forum is for all programming questions. The question does not have to be directly related to Linux and any language is fair game.

Notices

 05-06-2004, 12:34 AM #1 oulevon Member   Registered: Feb 2001 Location: Boston, USA Distribution: Slackware Posts: 437 Rep: Generating Combinations of Objects Hi, I'm creating a program to help analyze my poker games. One of the features I'm planning is to rank all the possible hands. In order to do this I need to generate every 5 card combination of a 52 card deck. In other words I have to generate 2,598,960 different hands. Anyone have any references on algorithms for generating combinations of objects? I'm doing this in Java, and I have a Card class that just has a value, and a suit, and then I have a Deck class that has an array of Cards (52). If anyone has any ideas, I'd appreciate it. Thanks.
 05-08-2004, 07:54 PM #2 gaffel LQ Newbie   Registered: Mar 2004 Distribution: debian sarge, 2.6.6, and ALSA finally works!! Posts: 18 Rep: the easiestway is to look at a simple example. If you create the combinations of three numbers from 6 numbers (20 combinations ), then you can see how the pattern builds up, just extend the idea to your 5 from 52 i.e Source cards, 1,2,3,4,5,6 as output want all three card combinations 1,2,3 1,2,4 1,2,5 1,2,6 Have reached maximum value on card 3, so increment card 2 1,3,4 Note, when increment card 2, card 3 must have a start value one higher 1,3,5 1,3,6 reached max again, inc card2, set card3 = card2+1 1,4,5 1,4,6 and again, inc card 2, set card3 = card2+1 1,5,6 card 2 is card3MaxValue-1, cannot go any higher with card 2, so now increment card 1, card2 = card1+1, card3=card2+1 2,3,4 inc card 3 2,3,5 inc card 3 2,3,6 inc card 3, card 3 = max, inc card 2 2,4,5 inc card 3 2,4,6 inc card 3, card 3 = max, inc card 2 2,5,6 card2=card3MaxValue-1, inc card1, card2=card1+1. card3 = card2+1 3,4,5 inc card 3 3,4,6 card3 at max, inc card 2 3,5,6 card2 = card3MaxValue-1, inc card1, card2 = card1+1, card3 = card2+1 4,5,6 card1=card2MaxValue-1, card2 = card3MaxValue-1, all cards at max value, end of sequenuce Hope this helps

 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 Off HTML code is Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post osio Linux - Software 1 09-16-2005 02:25 PM txtedmacs Linux - General 11 08-22-2005 07:03 PM will103 Linux - Software 2 09-11-2004 02:55 PM e_larkin Linux - Software 1 06-03-2004 11:48 PM XPediTioN Slackware 2 07-24-2003 06:37 PM

All times are GMT -5. The time now is 03:32 AM.

 Contact Us - Advertising Info - Rules - LQ Merchandise - Donations - Contributing Member - LQ Sitemap -