Exemplo n.º 1
0
        //Let a and b be the results of 2 tosses of the unfair coin. (Where true is heads, false is tails).
        //Now a is true with a probability of p, a is false with a probability of(1-p) (and the same with b).

        //          | b = true | b = false
        //a = true  | p* p     | p*(1-p)
        //a = false | p*(1-p)  | (1-p)(1-p)

        //Two of these probabilities are equal/fair, a && !b, and !a && b
        static bool BetterFlip(UnfairCoin coin)
        {
            bool a = coin.Flip();
            bool b = coin.Flip();

            if (a && !b)
            {
                return(true);
            }
            if (!a && b)
            {
                return(false);
            }
            //retry, one of the other 2 unfair possibilities
            return(BetterFlip(coin));
        }
Exemplo n.º 2
0
 //http://www.techinterview.org/post/3233458616/getting-a-fair-result-with-an-unfair-coin/
 public static void FairResultUnfairCoin()
 {
     UnfairCoin coin = new UnfairCoin(0.6);
 }