 Feature Articles

CodeSOD
 Most Recent Articles
 Ordering Off This Menu
 Duplication
 A Tip
 Around 20 Meg
 Image Uploading
 Junior Reordering
 A Sniff
 Classical Solutions
 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
Eurotwit.
Admin
The point is to practice in a programming language you're not that familiar with or to spend some time coding away from the project you might be bogged down in right now. There sure are a bunch of selfrighteous whiners around here.
The title is called "Knocking Me Off The Perch". That tells me that we are supposed to write some code to simulate the situation that Alex wrote about to prove why it won't work! We are knocking him off of the idea that he is stuck on because it seems like it should be a surefire way to win (if you ignore what you know about probability and are inebriated).
I took some time and played around with the concept in C++ even though I knew there would still be a (APPROXIMATE!!!) 5050 chance of winning regardless of the streak that was spun on the wheel previously... It was a nice distraction and it cleared my head for a while.
You guys are probably the ones that can't enjoy a movie because you sit there picking apart all the little technical errors that don't matter rather than just sitting back and enjoying the story as a whole.
/rant...
Admin
The key to this problem is realizing that the Perch is not a good strategy. On average, in ideal conditions, you'll lose.
Let's look at one particular condition. Let's say a table has 4 blacks in a row. The odds of that happening are 9/19 for each black, so 6561/130321 in total. Now what are the odds of the next chip being black? You might think not much at all, but if you do you've forgotten something: The odds of the last 4 rolls being black is 1, because it already happened! Instead, we look at the odds of getting a red next, and it's 9/19. It's always 9/19. No matter what previous rolls are, they have NO EFFECT on future rolls.
I don't know what the probability of turning $10 into $400 is, but it's very low considering that you can lose on the first try by 10/19 and then be broke (assuming that's part of the problem). There also is no limit on the number of times you can bet, so you could go from $10 to $20 and back to $10 for all eternity, before going on a winning streak and getting $400. So you probably have to find the limit of some equation to get the proper probability that takes this into account.
Admin
Is that so? Just as likely to get 100 red in a row than RBRBRB? Ok, if you know so much about probability, then let's go to a casino. I'll bet you $1000 that you won't see 100 red in a row....
Sure a table has no "memory" of the previous rolls, but that doesn't mean the probability of a given sequence is the same. The point is the probability of a sequence of 5 reds is more unlikely than a sequence of 4 reds. It's the sequence probability that you're working with here, not the probability of a single given roll.
Admin
<rant> I really enjoy these BYOC contests, all you people complaining about difficulty and or semantics instead of writing code are simply annoying. I've completed several of them, and in cases where the solution was posted, like in knights I came up with my own brute force version. These problems are meant to be fun little games, I'm using them to keep my Python sharp while I spend my days developing in C++. </rant> My version below is in python, I had to tweak it a little to interpret what to do after 5 bets(whether to reset the result counter) and to adjust the termination conditions as well.
Admin
TTTT is a 1/16 probability.
TTTTT is a 1/32 probability TTTTH is a 1/32 probability HTHTH is a 1/32 probability THTHT is a 1/32 probability
More generally, all sequences of a given length have the same probability.
Admin
It seems that this commenting system hates Prolog. But you, gentle reader, love Prolog. How could you not? Then go here to see a Prolog solution. What's not to love?
Addendum (20090819 13:49): Blast this demonic board! This is what happens when people fail to give Prolog the respect it deserves. The correct Prolog code is [url=http://pastebin.com/mec543ad]here[url].
Let's try posting the code, too!
Admin
Except GB and BG are the same thing. The question isn't concerning itself with the order in which they were born. Now your options are:
BB GG GB/BG (however you want to order it)
So #1 is already eliminated therefore it's 1/2. If the order was important 2/3 would be correct. The question is not asking "What are the odds the younger child is a boy?" which it would have to for your answer to be correct.
Admin
"Perhaps it was the alcohol, or maybe the elation from the first two bets, but the strategy seemed solid"
It was the alchohol. The strategy is as flawed as all others.
Admin
According to some movie I saw once, if you scream really loud, you can make it come up green. And then your boyfriend doesn't die. Or something.
Admin
Admin
thought that number (less the factorial sign) looked familiar, i just got a bill for that amount.
now 23,148,855,308,184,500!, that's a big number!
Admin
I believe the original posters points was that, yes, the odds of getting black, say, 10 times in a row are indeed very small  about 1/2^10 (technically a little less with the greens)  but they are exactly the same as getting any given randomsounding sequence. i.e. BBBBBBBBBB is small, but exactly the same as BRRBBRBBRR.
Admin
I saw an interview with the owner of a casino once in which he said, "If you have a lot of money to bet and you're feeling lucky, we'll meet you at the airport. If you have a system, we'll send a plane for you."
My daughter works in a hotel attached to a casino, and she once told me that there are a lot of people who come and play 2 slots machines simultaneously, put money in one, pull the handle, and while it's spinning put money in another and start it, then come back to the first. "That way," she said, "they can lose their money twice as fast." She also has many amusing stories about idiots, like the guy who came to the front desk one morning to ask if someone could give him a ride home to Utah, because the previous night he had gambled away his car. As a nervous father I was worried about her getting a job at a casino, but in reality it probably keeps her away from gambling: she sees how the only people making money at this are the casino owners.
Admin
Ok, well, seeing as I used to work in a casino, and saw this on a regular basis...
Here's my PHP code.
http://files.sourceguru.net/perch.txt
(captcha = acsi ... a limited version of ascii?)
Admin
I love how these BYOCs immediately turn into a googleoff, instead of a codeoff.
What kind of narcissistic, selfinflated egotist would grab a paragraph or quote off of (ffs!) wikipedia(‽) and claim it as their own? Apparently the kind that makes up a rather large percentage of this forum's members.
Meanwhile, Alex, come clean. We all know this was inspired by the reddit post about the spammer's variant of the Martingale "strategy" three days ago. Still, good show on the BYOC challenges. The troll potential is through the freaking ROOF!
grin
Admin
A drunk man normally has an even chance to take a 1 foot step to the left or a step to the right (no, he's not doing the Timewarp). Because we are sadists, we place a drunkard 1 foot to the right of a cliff. Also, the ground is slightly tilted, which means this poor besotted fellow is slightly (3%) more likely to take a step to the right. However, if he manages to wander 400 feet uphill, there is a kindly social worker who will take him away to rehab.
What are the chances that our drunk ends up dead at the bottom of a cliff?
Admin
Not at Caesor's Windsor. I lost $120 there last week and then they offered me something to drink ;/
Admin
In your way of reasoning, i.e. saying that GB is the same as BG, the weight of GB or the prior probability if you want, has to be taken into account. For GB/BG it is 1/2, whereas for GG it is 1/4. So now you have to divide 1/2 by (1/2 + 1/4) which still gives 2/3.
Admin
Some entertaining comments today! :D
I particularly enjoyed the Java implementation (implementing different strategies as different objects tickled me).
Also, thanks to the person who noted that this is a Random Walk. I hadn't heard that term before.
I implemented the simulation in PHP (before reading any of the comments). It seems readable and simple to me: http://pastebin.com/m2c191ce8
Anyways, good times.
Admin
I wrote this as a Console Application in C# using Visual Studio 2005.
Admin
So is the programmer supposed to just ignore the numerous statistical fallacies?
are you supposed to code it such that any time 4 blacks come up, a red is guaranteed to be next?
I think instead I'll just write a script that outputs your longterm expected bankroll:
echo "0";
There, done!
Admin
People are saying that roulette can't be beaten, that the House always wins. This is not true. There is at least one way to beat the House that doesn't involving rigging the wheel or punching the croupier when you lose or the like. And that is to abuse physics. In a casino, there is a physical wheel, after all, and you can certainly predict where the ball will land. This only applies if the casino lets people continue to place bets after the wheel is already spinning, of course, since the starting location and how hard the croupier pulls the wheel varies each game.
Some enterprising grad students actually pulled this off; I recommend "The Eudaimonic Pie" for more on this. It's an amusing book. This was back in ~1981, too, before computer miniaturization had really taken off... they had computers stowed in their phones, Maxwell Smart style, and the associate used radio signals to shock the better's hand in a specific spot to tell him where to bet. Pretty neat stuff.
The method was something like this: Divide the wheel into octants. Measure the speed of one revolution of the wheel  as in, click a button when 00 is at the bottom of the wheel, then click again when it has returned. Calculate which octant the wheel will stop at based on its speed (and a bunch of tests with a similar wheel and an estimate of the degree of tilt on the wheel). They never made tons of money off it due to having to research too many wheels, but at their best they were getting the octant right 1/3 of the time on a bet that's supposed to only pay off 1/8 of the time.
Admin
So much arguing over it. Of course it doesn't make sense, but drunk logic rarely does.
And no you aren't supposed to code it so that it 4 blacks > 1 red. code it like it'd happen in real life.
Never once made money... Matlab.Some assumptions: When you go to bet on a table you 'forgot' what tables had how what count. If bet>bankroll, you quit.
For some reason I can't get it to accept my code.. http://pastebin.com/mce5911a
Admin
Here's a javascript dabbling, it includes a wheel emulator.
I've yet to zero out yet though, so I'm not sure it's working right.
Admin
The odds are a bit better than this. Assuming a fixed 10 dollar bet, and starting with 10 dollars, the social worker is only 40 steps away. Also, the bet size is not in fact fixed, so we shouldn't force our random walker to only move one step at a time. Continuously betting the max gives a 1/64 chance to win outright, and in fact this would be the optimum strategy if our gambler was trying to win 320 dollars (or 640 dollars). As is, it gets a bit foggy as the gambler should start only betting what he needs to get to 400 at some point, giving him some room to recover on losses. Doesn't change the fact that when the house is against you, you want to make as few bets as possible to reduce the effect of the law of large numbers. It's much easier to get lucky 6/10 times than 60/100 times, for example, so we want to be making large bets.
Admin
I fixed my js, outcome is as expected, $0
Admin
It's funny watching it run:
played 39 times, highest cash on hand was 110 played 175 times, highest cash on hand was 200 played 1007 times, highest cash on hand was 420 played 79 times, highest cash on hand was 100
Admin
It was because of this that roulette wheels now have little pegs and ornamental obstructions so that the ball bounces around randomly before landing.
Admin
It's unclear how large an initial bet is when you approach a table. Is it always $10?
Admin
Are we not allowed to post the obligatory XKCD links anymore? SADFACE.
Admin
(Win at Roulette by predicting where the ball will land)
Yeah, I remember that Knight Rider episode where Michael held up his watch (camera) and Kitt figured out which number the ball would land on so he'd win a bunch of money.
No, I didn't have anything better to do in the 1980s.
Joe
Admin
So YOU'RE the guy the caused the world recession!
It's called the Martingale system. The downside is no matter the size of your bet, you're only winning one betting unit. Consequently the risk of ruin is high (e.g. 10 straight losses mean a $5120 bet on the board, and $5110 lost on the previous bets. If you win, you win $10240, or $10 net)
Admin
None of you ever played Grim Fandango? You don't win roulette because of random chance, it's fixed!
Admin
It's funny how you're attacking his statement (rightfully so) but incorrectly.
100 black followed by 100 red is infinitely more likely than RBRB repeated forever. 100 B followed by 100 R is just as likely as any other 200 spin sequence; it's your chances of predicting that (or any other 200 spin sequence) are effectively nil.
Those knowledgeable about probability are those who are keeping their money away from a casino.
Also your proposed bet is just stupid without odds. An even money bet on one side picking a 1 : 2^100 event  you're an idiot. I'd take your bet on the proper odds (you giving me $1000 if it happens; me giving you $1000 / 2^100 if it doesn't).
Admin
import java.util.*;
public class Perch {
}
Admin
I have tried "The Perch 1.0" twice; both times with play money at casino nights. 1.0 version means choose a color, bet every time, double next bet if you lose, retain half of all earnings if you win. As with all house based gambling, you always have to quit when you are ahead! This is why you should only play poker at casinos. Once you have payed your table fee, the casino does not care if you win someone else's money.
The first time it worked like a champ, I amassed $20,000 dollars starting with a $1,000 dollar stake for a $10 cover charge. Unfortunately, the bar would not accept the quoteunquote funny money as payment for beverages. They were selling Cuba Libres for $1 so I could live with that.
The second time I used "The Perch 1.0", I bet red, and black showed up 10 times in a row. The roulettier (I am not sure what you call them) said that she had never seen such a thing, but she happily continued to confiscate my funny money even though the last few, large piles of bills were stained with tears. (Or was it sloshed beer?)
P.S. I bet a straw poll of WTF readers will show that very few enjoy the mind numbing effects of slot machines. (Soma)
Admin
I wrote a bruteforcesolution in perl, just for testing randomness. After 1million runs with each starting with 10$, trying to get 400$ at 5 tables, I got: »Chance in this case is: 0.203800000000001%« I should mention, that I allowed to play at multiple tables at the same time.
Regards, H2
Admin
Tip for the Firefox users: if you hate that the preformatted code is double newlined put this to your userContent.css:
(if you don't know what userContent.css is than find file with name userContentexample.css on your disk, go to that folder, rename it to userContent.css and put the code from this comment into it. Save and restart firefox.)
Disclaimer: if something goes wrong, I'm really sorry :)
FAQ: Q: Nothing happened. A: You probably didn't restart firefox succesfully. The most reliable way to do this is to select File\Quit and than run firefox again.
Admin
Quick and dirty in PHP (SUPER Q&D, I'm at work so I threw it all together as fast as I could. The code is crap.) pastebin dot com / m3175c427
You can either do N number of runs for some statistics, or see what a single run looks like.
Stats example output:
and an example single run:
Dom
Admin
Here's my first crack at a Praxis on here. In C#. It loops through the tables one at a time, waiting for each one in turn to return fourinarow; this should be refactored to be asynchronous, but I didn't feel like going that far with it.
Also, Alex said the only output should be the final result, but this one prints out the bankroll, betting amount and result at every bet.
The betting amount is a random number between 10 and the current bankroll. It isn't restricted to multiples of 10, so it's possible the bankroll can be less than the minimum $10 bet without hitting zero. Therefore, we jump out of the loop when bankroll is less than $10.
Here are a sample losing and winning run, based on a starting bankroll of $100, two tables, and a desired bankroll of $400:
Bankroll = 100 Betting 19 on red: lose Bankroll = 81 Betting 71 on red: lose Bankroll = 10 Betting 10 on red: win Bankroll = 20 Betting 15 on red: win Bankroll = 35 Betting 11 on red: lose Bankroll = 24 Betting 22 on red: lose Final bankroll = 2
Bankroll = 100 Betting 23 on red: lose Bankroll = 77 Betting 20 on red: lose Bankroll = 57 Betting 49 on black: win Bankroll = 106 Betting 73 on black: win Bankroll = 179 Betting 123 on black: win Bankroll = 302 Betting 171 on black: win Final bankroll = 473
using System; using System.Collections.Generic; using System.Linq;
namespace ConsoleApplication1 { class Program { static void Main(string[] args) { // TODO: code for user input of parameters perch(100, 2, 400); Console.ReadKey(); }
}
Admin
This is a classic probability problem and large numbers does nothing to affect the probability. To say "I bet you the next 5 won't be red" is completely different than "I bet you the next one won't be red since the last 4 were." A roulette wheel has 36/38 red or black numbers, and 18/38 of each. Therefore, the probability of winning on any play is approx 47%
Based on the assumption that we go all in each play, if we lose once we're out (the strategy simply said "place a bet").
Therefore we must win 5.32~ consecutive bets in order to turn 10 into 400 [log2(40)]. So the probability of winning 5.32 consecutive bids is 1.87% (47%^5.32).
If I get a chance I'll post some probabilities of not going all in...
Admin
Gee, BYOC with TRWTF: Mentioning my hometown without having "The Windsor Ballet" be one of the major draws. :)
captcha consciousness: dolor
Admin
Perl hackers can win this, even if their code states perfectly clearly that they will always lose.
Admin
Admin
I ran the following:
5 tables, wait for 4 reds then bet $10 on black.
if that hits, go back to perch. If it doesn't bet $15 on black on the same table. Whether that hits or not, return to perch.
Start with $100, quit when you get to $0 or $400
I ran that a million times. What I got back was that it reached $400 39964 times out of a million. About 4% of the time.
given that you make $300 or lose $100, You've got about a 12% chance of making money by repeatedly playing.
Admin
Here's the best roulette strategy that I've ever seen:
'm going to give you a secret roulette system that really works. It will cut the house advantage to literally nothing, if you believe in it enough to never get frustrated and switch tactics. What I'm going to say may seem strange, but here goes.
First, never bet simply red or black. Also don't bet odd or even. These are equally poor, consistently losing wagers.
Second, don't be suckered into betting zero or double zero, despite what some experts may suggest. This may seem like you're betting with the house, but for technical reasons you are actually betting against the house  and you are taking the worst of it.
So, in order to negate the house advantage, you MUST stick to straight nongreen number bets. All odd red numbers turn out to be bad choices, based on over two trillion computer trials. Don't bet them.
All even black numbers fair poorly, and cannot be bet, for much the same reason, which I won't explain here.
Let's get straight to the moneysaving advice. Any bet you decide to make MUST cover only evenred or oddblack numbers. There are no exceptions.
Finally, you need to be very disciplined in excluding the number 30 and the group of consecutive numbers that begins with 11 and continues clockwise through and including 14.
This system may seem mystical, but I take gambling quite seriously, and this works for me.
Source: http://www.poker1.com/absolutenm/templates/mculib_articles.aspx?articleid=164&zoneid=3
Admin
I did something for this a while back, very similar to what is mentioned here
http://webpaul.net/content/InstaGamble.asp?bettingX=1&winningLimit=5&pocketMoney=1000&entryPoint=0
Admin
After having implemented this betting strategy (vb.net winforms) I've come to the conclusion that The Perch is an extremely poor betting strategy. In the example story the characters were lucky to have even doubled their money. More often than not one will lose the initial betting round.
Admin
My very long, object oriented, brute force method. After about 2030 tries, it has not won yet.