Photo Credit: discopalace @ flickrNot too long ago, I went up to Windsor, Ontario with my lawyer, Mr. Van Dress. Like my netbook, I never like to leave town without legal representation. Since there are really only three things to do in Windsor – drink, gamble, and buy Cuban cigars – we picked up some stogies, drank until we were confident we’d win, and headed over to the casino.

Before long, I had blown through far too much money on blackjack, and Mr. Van Dress had “invested” just as much on craps. Checking our pockets, I had $2 in chips remaining and he had $8, so we walked towards the roulette tables to place one last bet. Which table? and Black or Red? were the burning questions, and the answer seemed obvious: Table #3 and Red. After all, the table’s counter showed that black had just come up four times previously, so that meant red would have to come up next. Right?

We hastily pooled our chips and dropped $10 – the minimum bet – on red. And we won, collecting $20 in the process. But just then, we noticed a similar pattern on Table #1: red had just come up four times. So we rushed over and plopped half of our bankroll on black. And we won another $20.

Then we realized something. We had just discovered The Perch, a roulette strategy that could not fail. The rules were defined as follows.

  1. Perch someplace where you can see a number of roulette tables at once.
  2. As soon as a table shows four consecutive blacks or reds, swoop in and place a bet.
  3. If the bet is successful then return to the Perch. Otherwise, place another bet worth 150% of the previous bet (instead of $10, place $15).
  4. If the second bet fails, then shrug your shoulders and return to the Perch.

Perhaps it was the alcohol, or maybe the elation from the first two bets, but the strategy seemed solid: it seemed far too unlikely that the odds of five blacks in a row equaled that of red coming up. So, Mr. Van Dress and I followed the rules and, at the end of the night, walked away from the roulette tables with a combined $400.

Quitting While You're Ahead

After leaving the casino, Mr. Van Dress returned to his room and I returned to mine, but instead of going straight to bed, I decided to bring out the little netbook and write a little program to test The Perch. Even though it was 3:00 AM, and I was still a bit tipsy, and my development environment was a cramped keyboard typing VBScript into notepad.exe, I actually managed to whip up a quick script. It told me that, after placing a $10 bet, I could expect to win $23,148,855,308,184,500!

Clearly, there were a few bugs in my code and, after sobering up the next morning, I realized it was all an exercise in futility: there is no way to win at roulette. Mr. Van Dress, however, offered a different perspective.

“Wherein both parties understand the quote-unquote Law of Large Numbers, hereinafter referred to as quote-unquote, The Law, and both parties understand the Gambler’s Fallacy” he argued, “the so-called Perch strategy employs a different metric which may enjoin the aforesaid preclusions from fully being realized. Or in laymen’s terms: I’ve seen a heckuva lot more 4-in-a-rows than I have 5-in-a-rows.”

We left things at that. Partially because it’s hard to win an argument with an attorney, but also because I never got around to truly vetting The Perch.

Bring Your Own Code

Your practice for the day: write a function the plays The Perch strategy with a $10 minimum bet. There should be two three inputs (starting bankroll, number of tables, and desired ending bankroll) and a single output (final bankroll). The function should quit at zero or the ending bankroll. Keep in mind that a roulette table has 38 slots: 18 red, 18 black, a green zero, and a green double-zero.

The odds payout for betting on black or red are 1-to-1.

Bonus points: what is the probability of turning a $10 bankroll into $400 using The Perch?

In the spirit of always renaming things around here, the programming exercises here are now Bring Your Own Code. Thanks to "dhromed" for the idea and, should you not like the new name, now you know who to blame.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!