| « The Easiest Interview Ever & More | But I Didn't Change a Thing » |
Not 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.
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.
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.
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.
|
As it turned out, Automating the Knight's Tour was a bit more difficult than I had realized. When initially researching the problem, I saw a relatively simple algorithm and figured, oh yeah, I can do that! Of course, without knowing the trick... there was no way I could have solved it in a long coffee break or lunch break. Either way, I was most impressed by DaveC's Excel VBA solution. And just to note, The Perch is much, much easier than the Knight's tour. For an added challenge, you can pick a new language. |
|
I think the point of this exercise is not so much to program a mathematical proof of how and why you will go broke, but more to actually write the code that actually functions as described and watch it run. I suspect that if you do this you may be surprised at the results you will get. (and learn why some people actually win)
Back in the "before time" I coded up a battleship game in HP basic, you against the machine, no brains for the machine, just totally random, with a memory of where the pegs were. This got boring after a while (a very short while), so I made a few changes so the machine could play itself, fascinating for a few minutes, but a lot of paper was coming out of the teletype, so I eliminated all of the output except for the final win/lose results. Shortly after that I got a call from the system admin. Seems that eating up that kind of CPU time in 1975 was kinda frowned upon, go figure ;) The point is that I could have just put the variables down and calculated the result, but where is the fun in that. |
|
A bit late perhaps, but with my version, everyone can play!
http://www.itsacon.net/thedailywtf/perch.php Source: http://www.itsacon.net/thedailywtf/perch_s.php (not very impressive, wrote it during a 1-hour trainride...) |
| « The Easiest Interview Ever & More | But I Didn't Change a Thing » |