import java.util.Arrays;
import java.util.Random;

public class BirdsOnAWire {
	private static Random random = new Random();
	
	/**
	 * Four birds land at random positions on a finite length of wire.  
	 * Upon landing, each bird looks at its nearest neighbor.
	 * (a) What is the probability that a bird picked at random is looking at another bird that is looking at it?
	 * (b) What is the probability if there are n birds, with n > 4?
	 * Daniel P. Shine, "Birds on a Wire" (Journal of Recreational Mathematics, 10[3], 1978, p. 211.
	 * Compute 1-million-trial Monte Carlo estimates of the probabilities for n = 4-12, 20, and 30.
	 * 
	 * @param args (not used)
	 */
	public static void main(String[] args) {
		final int TRIALS = 1000000;
		for (int i = 4; i <= 12; i++) 
			monteCarloEst(i, TRIALS); 
		monteCarloEst(20, TRIALS); 
		monteCarloEst(30, TRIALS);
	}

	/**
	 * Perform a Monte Carlo estimate with numTrials simulations of the probability of 
	 * any of numBirds birds landing nearest to a bird that is nearest to it.
	 * Print the number of birds, and the probability that a bird is the nearest neighbor to its nearest neighbor. 
	 * 
	 * Recommendations:
	 * Since nearest is invariant to scale, have birds land randomly at positions on a length 1 wire.
	 * This can be accomplished by generating numBirds uniformly random doubles in the range [0, 1)
	 * and sorting them.
	 * 
	 * @param numBirds the number of birds to land at random points on a finite wire
	 * @param numTrials the number of Monte Carlo simulation trials
	 */
	public static void monteCarloEst(int numBirds, int numTrials) {
		// TODO
	}

}
