Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class E04FullHouseJokers {
- public static void main(String[] args) {
- String[] faces = { "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A" };
- char[] suits = { '♣', '♦', '♠', '♥' };
- char joker = '*';
- int currentFoundIndex = 0;
- String numberAsBinary = "";
- String[] currentCards = new String[5];
- String[] tempCards = new String[5];
- int counter = 0;
- for (int i = 0; i < faces.length; i++) {
- for (int q = 0; q < faces.length; q++) {
- if (q == i) {
- continue;
- }
- for (int suit = 0; suit < suits.length; suit++) {
- for (int suitTriple = 0; suitTriple < 3; suitTriple++) {
- currentCards[suitTriple] = faces[i] + suits[(suit+suitTriple)%suits.length];
- }
- for (int fourthSuit = 0; fourthSuit < suits.length; fourthSuit++) {
- for (int fifthSuit = fourthSuit + 1; fifthSuit < suits.length; fifthSuit++) {
- currentCards[3] = faces[q] + suits[fourthSuit];
- currentCards[4] = faces[q] + suits[fifthSuit];
- for (int j = 0; j < 32; j++) {
- tempCards = currentCards.clone(); // save current hand
- numberAsBinary = Integer.toBinaryString(j);
- currentFoundIndex = numberAsBinary.indexOf('1');
- while(currentFoundIndex != -1) {
- currentCards[numberAsBinary.length() - 1 - currentFoundIndex] =
- Character.toString(joker);
- currentFoundIndex = numberAsBinary.
- indexOf('1', currentFoundIndex + 1);
- }
- counter++;
- printCards(currentCards);
- currentCards = tempCards;
- }
- }
- }
- }
- }
- }
- System.out.println(counter + " full houses");
- }
- public static void printCards(String[] cards) {
- System.out.print("(");
- for (int i = 0; i < cards.length; i++) {
- if (i != 0) System.out.print(' '); // better formatting
- System.out.print(cards[i]);
- }
- System.out.println(')');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement