// Gambling Surprize 

/*

GAMBLING PROBLEM:

Suppose that you have 5 dollars to gamble

and that the house has twice as much, $10.

You play a dollar on each game, and your

probability of winning is 0.5 (coin toss).

You play until one of you wins all of it.

What is your probability of winning it all?

*/


// GAMBLING SOLUTION:

// Does show that gambling does not pay

// even if the odds are in your favor !


   double rand;    // random number

   int    amount;  // initial amount

   double winProb; // win probability


// Input, experiment with following

   amount  = 5; 

// winProb = 0.493; // dice craps

// winProb = 0.525; // impossible

   winProb = 0.50 ; // most fair


   while ((amount > 0) && (amount < 15)) { 

   // Exit when amount is 0 or 15

      rand = Math.random();

      if (rand < winProb) {

         amount ++; // Win a dollar

      }else{

         amount --; // Lose a dollar

      }//end if

      System.out.print (amount + " ");

   }//end while nobody is broke


// Report the final result

   if (amount == 0) {

       System.out.println ("You Lose all!");

   }else{ // (amount == 15)

       System.out.println ("YOU WIN ALL !");

   }//end if 

   

/* EXPERIMENT

Run this a number of times, and notice 

the maximum amount of wins in each run. 

(Why didn't you stop at that point, eh?)

Notice also the duration of the runs. 

(they vary widely, but what is the average).

Try this with different win probabilities,

and different initial values ($2?), etc. 


Simulate a run of very many times (millions)

to determine the probability of winning in the 

game of Craps (with 0.493 probability of win).

Also, in order to ultimately break even, 

what should be your probability of winning

a single game?

*/