Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 05-06-2004, 01:34 AM   #1
Registered: Feb 2001
Location: Boston, USA
Distribution: Slackware
Posts: 438

Rep: Reputation: 30
Generating Combinations of Objects


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.
Old 05-08-2004, 08:54 PM   #2
LQ Newbie
Registered: Mar 2004
Distribution: debian sarge, 2.6.6, and ALSA finally works!!
Posts: 18

Rep: Reputation: 0
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,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,6 reached max again, inc card2, set card3 = card2+1

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
keyboard + mouse combinations KDE osio Linux - Software 1 09-16-2005 03:25 PM
Key combinations that will stop a boot? txtedmacs Linux - General 11 08-22-2005 08:03 PM
key combinations to launch apps? will103 Linux - Software 2 09-11-2004 03:55 PM
Best combinations? e_larkin Linux - Software 1 06-04-2004 12:48 AM
ALT+ Combinations XPediTioN Slackware 2 07-24-2003 07:37 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:18 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration