import java.util.Arrays;

/**
 * Calculates the probability of rolling a full house. Five numbers form a full house if 
 * they can be partitioned into sets of 2-of-a-kind and 3-of-a-kind.
 *
 * @author Drue Coles
 */
public class FullHouse {

    public static void main(String[] args) {
        CupOfDice cup = new CupOfDice(5);

        // Monte Carlo simulation
        final int trials = 10_000_000;
        int wins = 0;
        for (int i = 0; i < trials; i++) {
            if (fullHouse(cup.roll())) {
                wins++;
            }
        }

        // Output probability with 2 digits of precision.
        double prob = (double) wins / trials * 100;
        System.out.printf("Full house probability: %.2f%% %n", prob);
    }

    /**
     * Returns true if a given array contains a full house.
     */
    private static boolean fullHouse(int[] a) {
        Arrays.sort(a);
        boolean b1 = a[0] == a[1] && a[2] == a[4];
        boolean b2 = a[0] == a[2] && a[3] == a[4];
        return b1 || b2;
    }
}