The following links may help navigating this page
WHO Disease Outbreak News

Martingale · 2006-07-04

Congratulations to Italia. Life is a game of chance, ain't it? The following groovy script shows how to play roulette the right way. Well, ok, this strategy only provides sure payoffs if 'assets' is infinite ... too bad

We have 'assets' and would like to carry home
'expassets' by going to the roulette table and
placing bets on either red or black. If we win, 
we do the same thing again. If we lose, we 
double the bet we place in order to cover losses. 
The Strategy should lead us to the expected 
assets in no time. ...or doesn't it?

/** Some start values **/
assets = 1000; //starting assets
expassets = 1500; //assets we want to carry home

b = false; //progress condition
bet = 1; //starting bet

/** Do the experiment **/
strres = new StringBuffer();
strres.append("win, coin, bet\n");

while (!b){
  /** toss the coin **/
  if (0.5 < java.lang.Math.random()){
    coin = true;} 
    coin = false;};

/** if coin true, collect payoff, otherwise adjust bet **/ if (coin){ assets += bet; bet = 1;} else{ assets -= bet; bet = 2*bet;}; /** Did we reach our goals? **/ if(assets >= expassets || assets-bet <= 0) b = true; if(assets-bet <= 0) println("Lost"); if(assets >= expassets) println("Won"); strres.append(assets+", "+coin+", "+bet+"\n"); } /** Write Results to .csv **/ writer = new "˜/results.csv" ); writer.write(strres.toString()); writer.close();

... well, mkay, however, the .csv file can be analysed most conveniently with R

Commenting is closed for this article.