 Feature Articles
 CodeSOD
 Error'd
 Forums

Other Articles
 Random Article
 Other Series
 Alex's Soapbox
 Announcements
 Best of…
 Best of Email
 Best of the Sidebar
 Bring Your Own Code
 Coded Smorgasbord
 Mandatory Fun Day
 Off Topic
 Representative Line
 News Roundup
 Editor's Soapbox
 Software on the Rocks
 Souvenir Potpourri
 Sponsor Post
 Tales from the Interview
 The Daily WTF: Live
 Virtudyne
Admin
Admin
I doubt it. Drunks are pretty much the canonical example in random walk scenarios, nothing to do with moralizing. Drunks near the cliff are onedimensional, drunks in the desert trying to make it back to the oasis are twodimensional, the drunk astronaut trying to get back to the space station is the threedimensional example, and... uh, I guess the drunken astronaut time traveler attempting to make it back to the space station at a specific point in time would be the four dimensional case?
Bonus question: Given an infinite amount of time, what's the percent chance of a onedimensional walker returning to the origin (no cliff)? Of a twodimensional random walker returning to the oasis? Of the threedimensional drunk astronaut making it back to the space station? The answers might surprise you.
Admin
Another Python implementation:
Admin
Cool story. One problem: as statistics tells us, just because previous events were anomalous does not indicate that the following event will be anomalous or normal. In other words, if you manage to flip a coin heads up ten times in a row, that does not mean the next flip should be heads or tails. The probability is still fiftyfifty.
The chance that a roulette table will get four reds in a row is small, but the chance of a roulette table getting four reds then a black or four reds then another red is the same:
0.5^4 * 0.5 = 0.5^5
You don't have to write a lick of code to see that.
Admin
Yes, everyone knows.
Admin
Don't know about theoryu or proof, but logic dictates....
Each spin is independent.
1)The likelihood of any spin being red is 9/19
2)The likelihood of 5 in a row being red (before any spins) is 9/19 ^5
2 confuses people, because they think it still applies if 4 spins have already been made, but they are so very, very wrong. The likelihood of the fifth spin being red is 9/19, irrespective of the previous 4 spins. Since the previous 4 spins are in the past, they are a certainty to happen (because they did) so the probability of them turning out as they did (in this case four reds) is 1.
If I remember simple arithmetic: 1 x 9/19 == 9/19
What's to prove? It can't be any other way. The likelihood of the past happening the way it did is 1 (or 100% if you like). There is no uncertainty (OOPs  let's not start on Schrodinger and Heisenberg et al  that's not what I mean). To think that the probability of something that happened happening is anything other than 100% we have to
Of course, where events are not independent there is another kettle of fish...
Admin
The Government already has his money. They claimed a percentage of it when he bought his Grog. That's the other revenue stream for the government.
Indecently, I hope the rest of your post was a touch on the sarcastic side. I have had a dollar for every time I've heard "I just wish I could figure out how to run my business as efficiently as the government is run." Currently I have 0.12 (I heard the "I just wish" bit)
Admin
Yup, just statistics and probability.
I think what mixes people up is they intuitively understand that getting red 5 times in a row is statistically rare, but they can never reconcile that on the 5th spin, the likelihood of being black isn't any higher than any other spin.
Admin
Admin
I'd just like to say that I appreciate the inclusion of a bonus challenge. Having separate beginner and advanced puzzles should keep everyone amused.
I haven't had time for this one yet, though, since I was a bit busy on a late but awesome solution to the knight's tour.
Admin
I wrote some Python 3 code to figure out the probability of going from $10 to $400, which turns out to be 0.25% if my code is correct.
My algorithm is to make a big array where each element represents the probability of the player winning from that amount of money. I start with arbtitrary estimates and then iteratively refine the array until it stabilises.
To simplify things a bit, I removed the irrelevant tables and divided all dollar amounts by 5.
Admin
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 1hour trainride...)
Admin
I tried a similar strategy once.
Me and my friend walked in with 100 Deutsche Mark (DM) each. We would look for tables with at least 5 blacks or reds in a row, then started betting the minimum (5 DM), doubling when we lost, until we won.
After 2 hours we walked out with a bit more than 200 DM each.
I left it at that, but my friend went back two weeks later and lost all on a row of 10 blacks, which  after he was broke  even exended to a series of 15 blacks.
Regarding the programming challenge: The mean value of your outcome when playing an infinite number of times is zero. In the long run the bank always wins.
Admin
Admin
I can't comment on the quality of the code, but the output looks great, is simple to use and clearly represents what is going on at each stage.
WIN!
Admin
I can't comment on the quality of the code, but the output looks great, is simple to use and clearly represents what is going on at each stage.
WIN!
Admin
My attempt to simulate RL as closely as possible:
To do this, I used threads to simulate a player and the roulette tables. Code and sample runs follow:
Sample output with $100 initial, four tables, and $400 goal.
Sample output with $10 initial, four tables, and $400 goal.
Using this strategy you have to be very lucky to start out with $10 and end up with $400!
Admin
I didn't read all the comments, a page and half was enough for me, but I did scroll thought to see if their was any hideous windows batch, their wasn't so here one is.
I tried to condense it a little........
Admin
Currently the code will simulate until the player exceeds the goal. This bug fix ensures player stops when he reaches the goal:
line 104: just after "/* Play as long as possible */"
line 178: just after "/* Double check  can player play? */"
Admin
For keener bonus points, after five runs, empirically the probability of winning was determined to be 5/16179 or about 1/3200  not so good.
Admin
A few years ago, someone pointed out that the Dallas Cowboys had lost every 10th game for many years in a row.
This is known as "mining past data to look for patterns". If you have a huge set of data (lots of teams and lots of years) to look through, you'll surely find some patterns.
The odds of 5 routlette blacks in a row starting from zero are different than the odds of one more black after 4 blacks in a row. The odds of the latter are 18 in 38.
Also, you shouldn't believe that a baseball hitter is "due" for a hit since he had struck out a bunch of times in the past. (Even though there is some ability here, it's partly random too.)
Finally, on a lighter note: a friend in college flipped a coin 20 times, and got the following sequence:
HTHTTHHTTTHHHTHHTTHH
He then calculated the odds of that particular pattern occurring, then concluded that a miracle had just happened, and switched his major to theology. :)
Admin
Nothing in the specifications says this is necessarily the case. Hence at least one if clause is needed to check if the better is happy with smaller end bankroll than initial. If this is the case expected pay will be initial bankroll (assuming that playing will be stopped after the current cash is equal or larger than desired end bankroll).
If the programmer decides that this kind of usage of the function is not allowed there should be an error check for bad input or at the very least an assert for this. Hence all solutions just returning zero (or 0  9) are in fact wrong or just plain bad programming if you believe end bankroll should always be larger than initial.
Continuing on kramthegram's rant, I have to point out that the task was to implement a working simulation of Perch strategy, not to point out that expected yield for this strategy as well is zero. Even in a simple case like this there is so much more fun that you can use a good implementation of the function for. For example you could simulate how much longer you can spend playing roulette using Perch strategy with given parameters than when just betting on a single (or random) colour or using Martingale.
And yet even the most knowledgeable about probability tend to buy insurances. Aside from statistics, there is another mathematical side to gambling, which is more intuitive when considering rationality of insurances: Game theory. For an individual in expected financial gain/loss is not the best parameter when considering whether or not to take an insurance. Simplified, pain of paying small monthly payments is much more tolerable than huge loss (a potential bankrupcy) if dung hits the fan. Therefore it is completely rational to buy an insurance even though expected payoff is negative.Same applies to gambling. Although all the games are in the favour of the house, if the bet is small enough and the jackpot is large enough (as it is in some lotteries), expected utility of playing might come up as positive, even if not considering the entertainment factor of the exitement. What is undeniably stupid, however, is playing with small bets for small wins unless it is done just for fun.
Admin
Yes, except that if you actually wrote the code and ran the simulations you'd see that this actually does work. The trick is it takes lots of games to get the stats to work out.
Just like Mythbusters, what seems obvious is not always the way it works....
If you only watch 50 games of roulette it's a tossup, even 500 or 1000 games it's not consistent. But you will notice a trend to winning more than loosing. However at a 1000000 games it's very consistent. You'll end up with about 3% green, 48.5% red and 48.5% black. About 2.6% of these rolls will be four in a row, 1.3% will be five in a row, and 1.2% six in a row.
This is why the bank always wins at the casino. Sure on the small scale a given player may win or loose, but over time, with 10000s of games the odds smooth out and get consistent. Games at the casino always favor the house over the long term, but using this technique you're actually getting better odds.
For 1000000 roulette games you'd have approximately 26500 four in a rows, 13000 five in a rows, and 12000 six in a rows. Starting with $100 bankroll and always betting $10 ($15 after a five in a row) you'd have around $195000.
Of course if your casino had 10 roulette tables running and each table averaged 1 game every 30 seconds, and you Perched for 16 hours a day, it would take you 52 days to go through 1000000 games.
Admin
Previously I submitted a "balanced" roulette wheel. It remembers its previous spins and then biases later spins to compensate. So each spin of RED makes it a little more likely to spin BLACK next. And it stays close to parity overall.
Adding a Perch simulator, I find that I can turn $10 into $400 9.16% of the time. Now if I can find a casino to install my special roulette wheels at their tables, I'll head on down and wager my life savings!
If I replace my wheels with a boring, memoryless wheel then my win percentage goes down around 0.26%. What a depressing universe that would be.
Admin
Surely it should be quote phrase being quoted ENDquote. You can't UNquote something, but you can end the quote.
Admin
Agreed I'm hooked!
Admin
Admin
The optimal way of playing is the Kelly Strategy, http://en.wikipedia.org/wiki/Kelly_criterion
The optimal strategy is to minimize the number of bets, since the expected win is negative. Hence, bet all your money, or the amount needed so that a win makes you reach your goal.
Admin
only three things to do in Windsor – drink, gamble, and buy Cuban cigars
I can vouch for the accuracy of this statement. Windsor is pretty boring if you aren't drinking or gambling.
Admin
I agree 100%. This is why I always keep a 'primed' coin in my pocket. I spend all day flipping this coin until I get eight tails in a row. Once I do that, I put the coin in my pocket because it is primed for heads. Then, when I disagree with my dippy friends, I end up telling them we should flip a coin for it. I always call heads, and because the coin flipped tails the last eight times, the chances of it being heads are 99.8% (that's one minus one half to the power nine).
Admin
Cool, but it doesn't work. I always end up broke! ;)
Admin
I disagree that n blacks in a row means that a n+1 black is equally likely as a red. That implies that the difference is 0, while red is actually lim x>inf (n/x) more likely. Clearly this is a critical difference.
Admin
Straight bets should pay off 35 to 1. So just a couple wins and you'd make 400.
Admin
I ran excel simulations as my weapon of choice. With 50 simulations, (starting at $10, 4 tables and a target of $400), I won merely 22% of the time, with the average number of rolls (on each table) 'til you reach the target: 50 (Maximum 209.
On the Losing side, the average loss time was merely 20 rolls, with losing everything on the first roll happening a shocking 6 times out of 50. Methinks Excel's Rand() function needs some work . . .
If you drop the bet amount to 25% of your bankroll, (or table minimums), you raise the winning percentage substantially to 34% (again 50 iterations). This also ups the amount of time 'til you reach the target to ~85 (on average). And if you lose, you will lose early (average: roll 10)
Switching to 5 in a rows has no real effect, except it takes longer (on average).
Interestingly, switching to 5, playing a 25% of your money (or minimums) and 1.5x last bet on first loss takes a really long time to win (on average 182 rolls/table (max 717?!)), and posts a win % of 68 (50 trials).
Admin
oops, made a mistake in the above, the last trial started with $20.
Also, follow up: Find optimum strategy by a) win percentage and b) # of rolls (less is better).
Admin
I won only one time (out of dozens). 2 tables, and it took 2,343 rounds!
Admin
Pretty decent but it doesn't keep increasing the bet by 1.5x each time. It should go 10 > 15 > 22 > 33 etc.
if (lose) then if 1.5BET =< WALLET then BET = 1.5BET else BET = WALLET end if
Admin
There is actually a good reason for that, though it is most likely inapplicable in a real casino.
Think about if a quarter comes up heads 50 times in a row. A priori, you do not know if the coin is fair or now; thus, the probability that the coin is far is 0.5. After observing the 50 run streak, the posterior probability that the coin is not fair is now much higher. (Similarily, the ABSENCE of long streaks also indicates that the coin is probably not fair. Human generated "random" sequences often have too few long streaks compared to short streaks). This is probably more formally described as the autocorrelation between flips of the coin; high autocorrelation indicates that the next flip is more likely to be heads given that the previous flip was heads, and vice versa.
Nicolas Nassim Taleb covers this more extensively in The Black Swan. A recommended read.
Admin
I set it to start with $100 and quite at $150 and got excited when I won six times in a row. :)
The final win:loss ratio was 15:10. Which sounds good until you add up the money, then it's 750:1000.
Admin
Started with 40 dollars. 663 Rounds later, I was broke.
Admin
So, you're saying the 1 in 2^100 event has a 1 in 2 chance of happening?
Admin
My last comment was in response to this:
Admin
In European Roulette (rules may differ from casino to casino), only inside bets like numbers other than 0 immediately lose on a single zero. Outside bets like colors are "imprisoned" meaning they're still there but cannot be retracted in full.
Examples:
Place 100 EUR on odd
0 comes up > 100 EUR are imprisoned
7 comes up > get 100 EUR back (not 200)
Place 100 EUR on odd
0 comes up > 100 EUR are imprisoned
24 comes up > lose 100 EUR
Place 100 EUR on odd
0 comes up > 100 EUR are imprisoned
0 comes up > 100 EUR still imprisoned
Switch 100 EUR from odd to red (switching from one outside bet to another is permitted)
0 comes up > lose 100 EUR (no triple imprisonment)
Place 100 EUR on black
0 comes up > 100 EUR are imprisoned
0 comes up > 100 EUR still imprisoned
Retract: You can get back half your imprisoned stake, the other half goes to the house, so get 50 EUR back, lose 50 EUR
So it's not as bad as immediately losing, but you cannot gain anything from this result either. ISTM that it's always best to retract bets after a second 0 because if anything other than zero comes up next, it makes no difference whether you've retracted half the sum and placed it on an outside bet again, or left it there. However, if a zero comes up, you're better off in the former case (you now have 50 imprisoned EUR instead of nothing at all). That said, it's best not to play Roulette unless you could predict upcoming numbers in some way...
Admin
You were using the wrong denominator. 1:15 is 1 / (15 + 1) or 6.25%. 1:31 is 3.125%, exactly half the previous probability.
Admin
1 play: profit = (.95(10)10) 10 plays: profit = 10*(.95(10)10) N plays: profit = N*(.95(10)10)
I find it amazing that people play these games... but being a professional poker player myself I have to appreciate it!
Blog tracking the longterm progress of my play: www.avoidthe9to5.com
Admin
1687 times and I was broke.
Admin
yeah, some times you may win... playing with initials $1000 I made $2000 most of the times betting $50 ( or $75 sometimes )... but I needed an average of 2000 ball rolls to make it, that is a lot of time
Admin
As anyone who has any familiarity with statistics knows, the odds on any number coming up on any given spin are exactly the same.
If the wheel is "fair" (and if your simulation's random number generator is truly random), then there is absolutely no reason that the fifth spin should come up either red or black  the outcomes of the previous four spins have no influence on the outcome.
While the red/black bet is the best one that you'll find in the casino, the odds are still with the house (note that there 18 red, 18 black, plus 0 and 00, which are green). So when you bet either red or black, there are 18 possible winning results, and 20 possible losing results.
So, with a red or black bet, your odds of winning are 20 to 18, or 1.111 to 1 against  on every spin, no matter what the results of the previous n spins were.
Admin
No.
The odds of red or black (20 to 18 against) are the same on every spin.
The outcome on previous spins has absolutely no effect on the outcome of the next spin.
This is a common mistake, but statistically incorrect.
Admin
I won the first one I tried... then I lost the next 30... which is as I expected... your odds are still 50%/50% no matter how many times it came up as one result or the other beforehand.