
-----------------------------------
_Dan_
Sat Jan 12, 2008 2:36 pm

Question Regarding a Card Combinations Program
-----------------------------------
Hello, I am a student studying first-year Java in high-school, and I was just wondering what would be the easiest solution to the following problem:

Definition of a Card:
Values {2-11}
Suits {5 Suits}

50 Cards in Total

I need to figure out (for a program for another class I am making) how to go through all possible 4 card VALUE combinations (suit is irrelevant) (order matters, hence if the values in a hand are 1,2,3,5 then the hand 5,3,1,2 would be identical, and should not be counted if 1,2,3,5 has already been counted).

The program I have right now (which is obviously incorrect) is:


        int

The problem is some hands are found multiple times :(.

Anxiously Waiting for Help,
Dan

-----------------------------------
Tony
Sat Jan 12, 2008 5:10 pm

RE:Question Regarding a Card Combinations Program
-----------------------------------
I think you might have some typos in there...


for (int second = second + 1 ; second < 50 ; second++)


System.out.print (values [fourth]); 
...
System.out.println (values [fourth]); 


There are different ways of preventing the same combinations from appearing. The least efficient, but probably the simplest to understand, method is to sort each hand and check if such order has previously appeared.

-----------------------------------
OneOffDriveByPoster
Sat Jan 12, 2008 9:16 pm

Re: Question Regarding a Card Combinations Program
-----------------------------------
You could simply ignore the first part of your code and the idea of 50 cards entirely.  Make your for loops generate each value combination that is in sorted order.  So value(card1) 300 million for loop runs, and each would have to check all of the hands before it. 

So value(card1) =.

-----------------------------------
OneOffDriveByPoster
Sun Jan 13, 2008 1:13 pm

Re: Question Regarding a Card Combinations Program
-----------------------------------
Ugh -.-.
Sorry I'm being careless, changed to >=.Happens to everyone.  I think there are some other minor problems though.  You have 5 suits and your suit values are not 0-4 so you need to adjust.  It really does save you a lot of trouble use 0-based indexing and start numbering things from 0 (convert on input and output).

-----------------------------------
_Dan_
Sun Jan 13, 2008 1:16 pm

Re: Question Regarding a Card Combinations Program
-----------------------------------
I got an array index out of bounds error before I posted it, so I fixed this :p, I also only checked 4 suits I believe, not 5, I fixed this before my last post as well :p, I'm making the program print out 1 in every 1 million hands it goes through, and I've calculated that it will take 16 minutes to go through all hands, so I guess that's bearable :p. Unless my calculations are incorrect, I think I don't need anymore help for now XD, once again thanks a bunch for all the help.

-----------------------------------
OneOffDriveByPoster
Sun Jan 13, 2008 1:39 pm

Re: Question Regarding a Card Combinations Program
-----------------------------------
I got an array index out of bounds error before I posted it, so I fixed this :p, I also only checked 4 suits I believe, not 5, I fixed this before my last post as well :p, I'm making the program print out 1 in every 1 million hands it goes through, and I've calculated that it will take 16 minutes to go through all hands, so I guess that's bearable :p. Unless my calculations are incorrect, I think I don't need anymore help for now XD, once again thanks a bunch for all the help.No problem.  FYI, I think this is the math way for how many 7-hands has 4-hands that are flushes:
5 suits, 10 values; nCr is how many combinations you can have if you choose r objects from n objects.
5 * (10C4 * 40C3 + 10C5 * 40C2 + 10C6 * 40C1 + 10C7 * 40C0)

-----------------------------------
_Dan_
Sun Jan 13, 2008 1:49 pm

Re: Question Regarding a Card Combinations Program
-----------------------------------
I already calculated the flushes and  prime ones actually :P (exactly the way you did), it was the other ones that were tricky, for example if you wanted to calculate how many straights occurred, you would need hundreds of cases I believe.

Weird... Here is the output I got:
All Divide: 29439900, 29.473971911529727%
All Prime: 35049250, 35.089813824781444%
Straights: 13721875, 13.737755845757697%
Flushes: 3337260, 3.3411223374220596%
Straight Flushes: 1102220, 1.1034956409609509%
Prime Flushes: 1240701, 1.24213691026827%
Divide Flushes: 361262, 0.36168010219814106%
Total: 99884400

The flush % is incorrect :S.
It should be: 11,399,400 and a % of 11.41..

And as for primes. The math would be:

i) 4 Primes: 25C4 * 25C3
ii) 5 Primes: 25C5 * 25C2
iii) 6 primes: 25C6 * 25C1
iv) 7 primes: 25C7 * 25C0
i+ii+iii+iv = 49,942,200

With a percentage of 50%

Must be something wrong with the method :S.

-----------------------------------
OneOffDriveByPoster
Sun Jan 13, 2008 1:57 pm

Re: Question Regarding a Card Combinations Program
-----------------------------------
The flush % is incorrect :S.
It should be: 11,399,400 and a % of 11.41..I had to fix your loop for populating the suits[] array in main().

-----------------------------------
_Dan_
Sun Jan 13, 2008 1:58 pm

Re: Question Regarding a Card Combinations Program
-----------------------------------
Oh ok, I'll take a look, I also made the prog more efficient by making the prime hand checker similar to the new flush one.

Wait what's wrong with it -.-.

Here's my new code by the way:
import java.awt.Color;
import hsa.Console;
import java.util.*;

/** The "Check" class.
  * Purpose:
  * @Author
  * @Last Updated:
 */
public class Check
{
    public static boolean isPrime (int value)
    {
        if (value < 4)
        {
            return true;
        }
        if (value == 5 || value == 7 || value == 11)
            return true;
        return false;
    }


    public static boolean allDivideC (int fCard, int sCard, int tCard,
            int foCard, int fiCard, int siCard, int seCard)
    {
        int values

-----------------------------------
OneOffDriveByPoster
Sun Jan 13, 2008 2:06 pm

Re: Question Regarding a Card Combinations Program
-----------------------------------
I could tell you, but try printing the array to see first.

-----------------------------------
_Dan_
Sun Jan 13, 2008 2:16 pm

Re: Question Regarding a Card Combinations Program
-----------------------------------
Testing the allPrime and flush hands now.

import java.awt.Color;
import hsa.Console;
import java.util.*;

/** The "Check" class.
  * Purpose:
  * @Author
  * @Last Updated:
 */
public class Check
{
    public static boolean isPrime (int value)
    {
        if (value == 2 || value == 3 || value == 5 || value == 7 || value == 11)
            return true;
        return false;
    }


    public static boolean allDivideC (int fCard, int sCard, int tCard,
            int foCard, int fiCard, int siCard, int seCard)
    {
        int values

-----------------------------------
_Dan_
Sun Jan 13, 2008 2:35 pm

Re: Question Regarding a Card Combinations Program
-----------------------------------
Ok it's working, now I just need to figure out what's wrong with the prime one :S.

-----------------------------------
Tony
Sun Jan 13, 2008 2:45 pm

RE:Question Regarding a Card Combinations Program
-----------------------------------
yes, you don't need any of the for-loops.

similarly you don't need 4 for-loops for straightC, one will do just fine (Hint: sort the 7-card pool before the loop) (Hint2: the loop is from 0 to 3)

-----------------------------------
_Dan_
Sun Jan 13, 2008 2:51 pm

Re: Question Regarding a Card Combinations Program
-----------------------------------
Arg I forgot about that! I used a similar method for a poker hand problem in comp sci class -.-.
Updated.

But why are the numbers for the all prime hands incorrect?

Also is my straight code correct -.-, it's giving me different numbers.
import java.awt.Color;
import hsa.Console;
import java.util.*;

/** The "Check" class.
  * Purpose:
  * @Author
  * @Last Updated:
 */
public class Check
{
    public static boolean isPrime (int value)
    {
        if (value == 2 || value == 3 || value == 5 || value == 7 || value == 11)
            return true;
        return false;
    }


    public static boolean allDivideC (int fCard, int sCard, int tCard,
            int foCard, int fiCard, int siCard, int seCard)
    {
        int values

-----------------------------------
_Dan_
Sun Jan 13, 2008 6:02 pm

Re: Question Regarding a Card Combinations Program
-----------------------------------
Damnit, I remember why I needed the flush to go through all possible combinations. I need to also check whether a 4 card hand is both a flush AND a straight/all prime, I also need to check whether a hand is a fractor (all cards in the hand are factors of the largest) AND all prime.

Do I have to do the following now?:

1. Make an isStraightFlush method
 -Make a custom sorting method that sorts the 4 card hands by numerical value, but also changes the location of the  suits int the array as well
 -Sort the hand using the custom sort, check if there are 4 consecutive values and 4 consecutive suits in every possible 4 card combination

2. Make an is flushPrime method
 -Goes through every possible 4 card hand, checks to see if all of the suits are the same, and all of the values are prime

3. Fractor prime
-Goes through every possible 4 card hand, checks to see if the values all divide into the highest AND are prime

Or is there a better/easier way of doing this :S (the above will take quite a while...).

-----------------------------------
OneOffDriveByPoster
Sun Jan 13, 2008 6:55 pm

Re: Question Regarding a Card Combinations Program
-----------------------------------
2. Make an is flushPrime method
 -Goes through every possible 4 card hand, checks to see if all of the suits are the same, and all of the values are primeI'll focus on this one as an example.  You can use the counter method that was used with plain flushes but only increment when the value is prime.  Try to see if thinking differently about the problem helps.

Also:Goes through every possible 4 card hand, checks to see if the values all divide into the highest AND are prime...isn't that just 0?

-----------------------------------
_Dan_
Sun Jan 13, 2008 7:13 pm

Re: Question Regarding a Card Combinations Program
-----------------------------------
...isn't that just 0?
Quadruple Primes :). 2,2,2,2 all divide into the highest value, 2, and are all prime :p. Though I could just check if all the values are identical, and that the first value is prime, this method is easy to create.

I'll focus on this one as an example. You can use the counter method that was used with plain flushes but only increment when the value is prime. Try to see if thinking differently about the problem helps. 
Good idea XD, ok finished this part.

So now all I need is the Straight  Flush checking method.

-----------------------------------
OneOffDriveByPoster
Sun Jan 13, 2008 7:34 pm

Re: Question Regarding a Card Combinations Program
-----------------------------------
So now all I need is the Straight  Flush checking method.You don't need to go through all 4-hands with this one either.

-----------------------------------
_Dan_
Sun Jan 13, 2008 8:27 pm

Re: Question Regarding a Card Combinations Program
-----------------------------------
Do I HAVE to make a custom sort -.-.

-----------------------------------
_Dan_
Sun Jan 13, 2008 11:59 pm

Re: Question Regarding a Card Combinations Program
-----------------------------------
The program says there are no straight flushes, what's wrong with my method :S?

public static boolean straightFlushC (int fCard, int sCard, int tCard, int foCard,
            int fiCard, int siCard, int fCardV, int sCardV, int tCardV, int foCardV,
            int fiCardV, int siCardV)
    {
        int suits
