LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


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

Rep: Reputation: 30
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.
 
Old 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: 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,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
 
  


Reply



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 02:25 PM
Key combinations that will stop a boot? txtedmacs Linux - General 11 08-22-2005 07:03 PM
key combinations to launch apps? will103 Linux - Software 2 09-11-2004 02:55 PM
Best combinations? e_larkin Linux - Software 1 06-03-2004 11:48 PM
ALT+ Combinations XPediTioN Slackware 2 07-24-2003 06:37 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:36 AM.

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