Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
import java.lang.*;
public class Riddler
{
public static void main(String[] args)
{
int goal = 10;
int trials = 1000000000;
int player1Score = 0;
int player2Score = 0;
int player1Wins = 0;
int coin;
for (int i = 0; i < trials; i++)
{
player1Score = 0;
player2Score = 0;
while (player1Score < goal & player2Score < goal)
{
coin = (int)(Math.random() * 2);
player1Score = player1Score + coin;
if (player1Score > (goal - 1))
player1Wins++;
coin = (int)(Math.random() * 2);
player2Score = player2Score + coin;
}
}
System.out.println((player1Wins * 1.0) / trials);
}
}