News for hackers. Stuff that matters.
Re:Parrondo's Paradox: How two ugly parents can make a beaut... by blameless on Thursday August 23, 2012 @10:25AM (#4422518)
I'm unable to reproduce the results. Balance is always negative. What's wrong with my code?

  // for a graph
  var balances = [];

  // constants
  var winnings =  1, 
      losses   = -1, 
      epsilon  = 0.05;

  function play(probOfWinning) {
      return Math.random() < probOfWinning ? winnings : losses;
  }

  for (var experiment = 0; experiment < 100; experiment++) {
      var balance = 0;
      for (var flip = 0; flip < 1000000; flip++) {
          if (flip % 3 == 0) { // game A
              balance += play(0.5 - epsilon);
          } else { // game B
              balance += Math.round(balance) % 3 == 0 ? play(1/10 - epsilon)
                                                      : play(3/4  - epsilon)
          }
      }
      balances.push(balance);
  }
Re:Parrondo's Paradox: How two ugly parents can make a beaut... by SoftwareMaven on Thursday August 23, 2012 @05:16PM (#4424897)
The problem is you are using a rounding of the balance across the million tries to decide on game B. The choice of which game B to use need to not be dependent on the other experiments.
Re:Parrondo's Paradox: How two ugly parents can make a beaut... by maxerickson on Thursday August 23, 2012 @10:45AM (#4422628)
You are playing 100 games of 1 million rounds each.

The graph in the article shows the average state of each round over 1 million games.