Advertisement
Guest User

_04_FullHouseWithJokersWithoutRepetition

a guest
Sep 16th, 2014
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.15 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.LinkedHashSet;
  3.  
  4. public class _04_FullHouseWithJokersWithoutRepetition {
  5.  
  6.     public static void main(String[] args) {
  7.  
  8.         String[] cards = { "2", "3", "4", "5", "6", "7", "8", "9", "10", "J",
  9.                 "Q", "K", "A" };
  10.         String[] suits = { "♣", "♦", "♥", "♠" };
  11.         LinkedHashSet<String> fullHouseSet = new LinkedHashSet<String>();
  12.         for (int card1 = 0; card1 < cards.length; card1++) {
  13.             for (int card2 = card1 + 1; card2 < cards.length; card2++) {
  14.                 for (int suit1 = 0; suit1 < suits.length; suit1++) {
  15.                     for (int suit2 = suit1 + 1; suit2 < suits.length; suit2++) {
  16.                         for (int suit3 = suit2 + 1; suit3 < suits.length; suit3++) {
  17.                             for (int suit4 = 0; suit4 < suits.length; suit4++) {
  18.                                 for (int suit5 = suit4 + 1; suit5 < suits.length; suit5++) {
  19.  
  20.                                     for (int bit = 0; bit < 32; bit++) {
  21.  
  22.                                         String[] fullHouse1 = {
  23.                                                 cards[card1] + suits[suit1],
  24.                                                 cards[card1] + suits[suit2],
  25.                                                 cards[card1] + suits[suit3],
  26.                                                 cards[card2] + suits[suit4],
  27.                                                 cards[card2] + suits[suit5] };
  28.                                         String[] fullHouse2 = {
  29.                                                 cards[card2] + suits[suit1],
  30.                                                 cards[card2] + suits[suit2],
  31.                                                 cards[card2] + suits[suit3],
  32.                                                 cards[card1] + suits[suit4],
  33.                                                 cards[card1] + suits[suit5] };
  34.                                         for (int num = 0; num < 5; num++) {
  35.                                             if ((bit & (16 >> num)) == 16 >> num) {
  36.                                                 fullHouse1[num] = "*";
  37.                                                 fullHouse2[num] = "*";
  38.                                             }
  39.                                         }
  40.                                         Arrays.sort(fullHouse1);
  41.                                         Arrays.sort(fullHouse2);
  42.                                         String fullHouse1String = Arrays
  43.                                                 .toString(fullHouse1);
  44.                                         String fullHouse2String = Arrays
  45.                                                 .toString(fullHouse2);
  46.                                         fullHouseSet.add(fullHouse1String
  47.                                                 .replaceAll("[\\[\\],]", ""));
  48.                                         fullHouseSet.add(fullHouse2String
  49.                                                 .replaceAll("[\\[\\],]", ""));
  50.                                     }
  51.                                 }
  52.                             }
  53.                         }
  54.                     }
  55.                 }
  56.             }
  57.         }
  58.         for (String ithem : fullHouseSet) {
  59.             System.out.printf("(%s)%n", ithem);
  60.         }
  61.         System.out.printf("%s full houses", fullHouseSet.size());
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement