import java.util.concurrent.ThreadLocalRandom;

/**
 * Calculates the probability of winning the Sum Game. In this game, the player rolls 
 * three dice and wins if one of the rolled numbers equals the sum of the other two.
 *
 * @author Drue Coles
 */
public class SumGame {

    public static void main(String[] args) {

        final int games = 10_000_000; // number of games to simulate
        int wins = 0;
        
        for (int i = 0; i < games; i++) {
            if (sumGame()) {
                wins++;
            }
        }
        
        // Calculate probability of winning.
        double prob = (double) wins / games * 100;
        System.out.printf("Probability of winning the Sum Game: %.2f%% %n", prob);
    }

    /**
     * Simulates the Sum Game.
     * 
     * @return true if the player wins and false otherwise
     */
    private static boolean sumGame() {
        ThreadLocalRandom rand = ThreadLocalRandom.current();
        int a = rand.nextInt(1, 7);
        int b = rand.nextInt(1, 7);
        int c = rand.nextInt(1, 7);
        return a == b + c || b == a + c || c == a + b;
    }
}