I am currently trying to develop an application where I need to find all combinations of 2 cards in a standard card deck of 52 cards. These combinations will be generated in four nested for loops.
When you calculate the possible combinations using simple math you will get:
Quote
52! / ( 2!(52-2)! ) = 1326
now my code currently looks like this:
for (int c3_1 = 2; c3_1 <= 14; c3_1++){ // first cards value
for (int c3_2 = 1; c3_2 <= 4; c3_2++) { // first card suit
for (int c4_1 = 2; c4_1 <=14; c4_1++){ // second card value
for (int c4_2 = 1; c4_2 <=4; c4_2++){ // second card suit
// check if the cards are the same
if (c3_1 == c4_1 && c3_2 == c4_2){
break;
}
else {
card_count++;
}
}
}
}
}
however when I print out the card count I get 2574, which is way to many combinations. As I've shown you it should only be 1326.
I allready done so the generated cards cant be the same.
So how do I do this? anyone know what the problem is here?
Thanks alot!
Jacob


Sign In
Create Account


Back to top









