 Feature Articles
 CodeSOD

Error'd
 Most Recent Articles
 Mirror mirror
 ROUS
 Groundhog Day
 Ride Ride Ride
 Grasshopper
 Patience
 One If By Land
 Shippingship
 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
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.
Admin
ALl sounds very Fear and Loathing to me... road trip, drinking and gambling with your lawyer!
Admin
3rd? I miss getting these early.
Admin
Ha, and here I was flipping a coin with Guidenstern and Rosencrantz by the end of the second paragraph.... wait until he gets a load of those bats.
Admin
Admin
What the hell does quoteunquote The Law of Large Numbers mean?
Surely that should be quote The Law of Large Numbers unquote.
quoteunquote bothers the crap out of me. The whole point of it is to quote a phrase, but if you simply say quoteunquote before the phrase how do we know when the phrase is finished?
This isn't grammer Nazism, it's logic Nazism.
Admin
Ok, I've got the program ready, but I'm not sure where exactly to place my CasinoEmployeesTakeYouToALittleBasementRoomAndSweatYouException
Admin
Especially when you can actually type quotes: "The Law of Large Numbers".
Admin
OK, ignoring the irrelevant waffle about the multiple tables and runs of luck, here's a perl golf version at 92 characters, assuming you can bet any integer number of dollars above 10.
sub p{my($b)=@_;while($b>9){my$t=10;while((rand 38)<18){$b+=$t;$t=int($t*1.5);}$b=$t;}$b;}
Admin
Admin
Also, the odds are 18/38 for red, 18/38 for black and 2/38 for green...
Admin
The roulette table has NO MEMORY of the previous sequence of events (black or red). Read this several times till you understand this concept.
Randomness is not the roulette table keeping a tally of all the reds and blacks in sequence and making sure there are the same number of each (ignoring the greens which I'll get to in a minute) or a fairlooking alternation of red and black sequences.
The sequence of random black and red is truly random  100 black followed by 100 red is JUST AS LIKELY as REDBLACKREDBLACK (repeated forever) or RRRRBBBBRRRRBBBB...or any other combination.
Each subseqent outcome is completly unaffected by the previous colour.
As far as the odds being 1:1  the 2 greens are how the house winds. Yes  there are equal number of reds and blacks, so 1:1 payout looks like a good deal. However, there a 2 green possibilites on the table (i.e. neither red nor green)  this is why the house always win on average.
Suggest your coding competition is scrapped in favour of reading 'Probabilities for Dummies'
Admin
My first little book on mathematics did a good job of explaining how roulette works, and how roulette strategies don't. It ended with advice along the lines of: rather than play roulette, flush your money down the toilet; it's equally effective and saves the hassle of getting to the casino.
Admin
Yours Yazeran
Plan: To go to Mars one day with a hammer
Admin
"Suggest your coding competition is scrapped in favour of reading 'Probabilities for Dummies'"
Methinks the mention of "gambler's fallacy" in the original post means he already knows and he's just trolling for responses like yours ;)
Admin
I'm afraid I don't understand the point of this problem.
The chances that something will hit a certain colour on the next roll are exactly the same no matter what was rolled before. So coding a solution to this will wind up exactly the same as if you just coded regular roulette.
Admin
Suggest that you have never actually been gambling before. The lawyer in the story already states that The Perch was thought up in a situation "[w]herein both parties understand...the Gambler’s Fallacy" so it's useless to get on your soapbox and preach about a basic tenet of probability. I'm pretty sure we all know that one. This is about having fun, one of the things you're supposed to do at a casino (along with losing all your money due to the aforementioned Gambler's Fallacy).
Admin
I was thinking that too but I am assuming that is part of the joke and the idea was to come up with some WTF code?
Admin
Also, it saves you the cost of renting a tux, so it might even be less money lost.
Then again, calling a plumber to fix the drains might reverse that...
Admin
It should be noted that you may need the entire worlds gross national product available for this to work.... (Not to mention that the casino should not have a limit on the maximum bet you can make, which incidentally exists exactly because of the recipe described above)
Yours Yazeran
Plan: To go to Mars one say with a hammer
Admin
And grammer (sic) is spelled grammar.
Captcha: Capio which sounds Italian, which reminds me of fascism.
Admin
Woah woah woah, slow down. The chance of the combined event of getting black 100 times in a row is EXTREMELY low, on the order of 1 in 2^100 (let's ignore green). However, if it has already been black 99 times in a row, the chance of it being black again is still 1 in 2.
Admin
This is the same problem for any game like this, black jack is a perfect example.
Take your initial $10 bet. If you lose place a $20 bet. Continue doubling the bet until you win. Congratulations! You just won $10...
That's why most tables have a min and a max, to limit the amount of times you can double up.
Admin
Admin
He has, indeed, seen a lot more 4inarows than 5inarows. Approximately twice as many.
Admin
Coincidentally, that is also the exact method used to dispose of all your money.
Admin
Oh, you're talking about American Roulette. Not Roulette. Just like American Football isn't usually played with one's foot...
scnr...
Admin
Software requirements are getting vague these days... oh wait, they always were.
Admin
Ok, let me write this function then. Firstly, the number of tables is irrelevant as the chance to with is 50% regardless of tables. Secondly, you don't specify how many runs to do in a single function, and provide no way to store state between runs, so I can only end the function when you can't play anymore. And of course, you can't play anymore when you reach $0.
So here's my function in C:
And for fun, here it is in Haskell:
And why not in perl:
Why yes, I am quite pedantic, how did you know?
Captcha: ludus, nearly ludicrous?
Admin
The quote wasn't saying that the odds of winning are 1 to 1, ie 50%. It was saying that the payoff for winning the bet are 1 to 1. If you bet $5, you get your original $5 back plus another $5. You win the amount of your bet.
Admin
The specification is incomplete. "As soon as a table shows four consecutive blacks or reds, swoop in and place a bet." How big? Should it always be the minimum? Is the intention that you should play $10 if you have exactly $10 or >$25, and otherwise you should play the amount you have (since you won't have enough to place the second bet if you lose the first)? Or is part of the challenge figuring out the optimum (for some metric) amount to bet each time?
Admin
Returning 0 doesn't work. The minimum bet is $10. Your final total should be distributed between 09.
Admin
There's no need for any code, a calculator will do perfectly well.
In order to win $400 starting $10, with winning bets paying even money, the quickest way to get there is to win 6 times in a row, betting all you have each time (so you could get $640, actually).
The odds for each bet are 18/37 (for normal roulette wheels with one zero), or 18/38 (for American roulette wheels with a zero and a double zero).
Raising those numbers to the 6th power gets you the odds: 0.013 probability for normal wheels 0.011 probability for American wheels
So about 1 chance in 100.
As we all know, what the wheel span last time is completely irrelevant  although it is truly surprising the number of people who don't actually believe that in their heart of hearts :)
If you don't bet the whole lot every time it gets more difficult to work out :)
Admin
http://wizardofodds.com/askthewizard/bettingsystemsmartingale.html
Admin
Yes, the outcomes of two tosses (turn? role? death spiral?) of the roulette. Yes, the sequence is completely random. That does not mean, however, that all sequences are equally likely to occur.
For an entertaining summary, see: http://www.ted.com/talks/lang/eng/peter_donnelly_shows_how_stats_fool_juries.html
Admin
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.
Admin
echo '$0'
Admin
Not so, because you may end up with greater than zero but insufficient to meet the $10 minimum bet on the next spin...
Admin
After a night like that, I'd probably spend that $09 on drinks. But yes, good point.
Admin
BTW, in the calculations above, I left out step 3 (the betting 150% of a losing bet), as it wasn't clear when to stop betting*, so there's no way to work out how many bets can be placed.
Admin
An American football is a foot long.
Admin
The probability is low, however equal any other combination of the same length.
Admin
Yes, it's ludicrously low. But it's the EXACT SAME as the odd of getting RBRBRB... for 100 bets in a row, or getting RRRRBBBBRRRRBBBB... for 100 bets, or ANY exact sequence of 100.
Admin
ARGH. Three identical answers to the same question, and this WTF POS forum doesn't let me delete my post...
Admin
I can't get this method to produce any winnings (like I suspected from the start). Most of the time I lose the first bet so I don't get anywhere. Also the complicated method of playing the against "streaks" of rolls does not have any greater chance of winning (as prediced). Still sometimes I can make a series of wins.
But most importantly the series always converges on $0, so it is impossible to keep this going forever.
I'm not posting code, because it's messy and I have to get back to work.
Admin
"I’ve seen a heckuva lot more 4inarows than I have 5inarows."
No, you've seen slightly less than 1/2 the number of 5inarows as 4inarows (would be exactly 1/2 except for greens.
Admin
And by DaveC, I assume you mean BradC? Thanks!
After cheating and reading the Wikipedia page, I started a second Excel VBA version that uses the Warnsdorff's algorithm (cool algorithm, Warnsdorff!! Much faster and more efficient than brute force!).
I got the basic algorithm to work, but didn't get as far as designing a backupandretry if it didn't work from the start.
Admin
In light of the losing condition be less than $10, here's my revised solution:
Admin
Admin
The point of this "practice" clearly isn't to try coding a solution, but being a good enough programmer to analyze the problem first and realize there's no pattern to roulette so no code needs to be written.