Archive for October 2008

You are browsing the www. Michael Righi .com archives for October 2008

Simulating the Monty Hall Problem (1)

In 1990, Marilyn vos Savant, the woman with the world’s highest IQ, Parade magazine contributor, and wife of Dr. Robert Jarvik, the inventor of the Jarvik artificial heart, posed the following question to her magazine readers:

Suppose you’re on a game show, and you’re given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say No. 1, and the host, who knows what’s behind the doors, opens another door, say No. 3, which has a goat. He then says to you, “Do you want to pick door No. 2?” Is it to your advantage to switch your choice?

This brain teaser is often referred to as the Monty Hall Problem, or the Monty Hall Paradox, because of its obvious resemblance to the game show Let’s Make A Deal. (On a quick tangent, a friend from high school was named Adeel. I’ve always joked that on the night he was conceived his parents said to one another, “Let’s Make Adeel!” He never found this as funny as I did.)

This puzzle was most recently made famous in the movie 21, when it was posed by Kevin Spacey’s character to one of his students. The student gives the correct answer, which I’ll point out in a moment. Before I do, let me tell you about my initial reaction to this problem. A few years ago I was reading a math book that brought up the Monty Hall question. My first response to the question of whether it was better to switch doors or stick with your first choice was, “it doesn’t matter.” After all, if it always comes down to two doors in the end then isn’t it always going to be a fifty-fifty chance?

The answer that the book provided, and the answer that the student gives in 21, is that you are better off switching doors every time. In fact, you double your chances of winning if you switch doors!

When I read this answer I couldn’t believe it. It didn’t make any sense to me. In fact, I decided that the only way I would believe it was if I saw it with my very own eyes. So, I did what any geeky programmer would do. I opened up a text editor and whipped together a quick little Java program that simulated the game. I had the program play the game 2,000 times, simulating a game where the contestant switches 1,000 times and doesn’t switch the other 1,000 times. Sure enough, when the player switched doors they won approximately 66% of the time, and when they didn’t switch doors they won only 33% of the time.

At this point I was convinced that you were better off switching doors, but it took me a little while to grok the reason for why. Here’s how I now like to explain it…

Let’s imagine a scenario where the contestant picks door number one. There are now two sets of doors: The set of chosen doors (a set containing one door) and the set of unchosen doors (a set containing two doors.) (BTW, “unchosen” isn’t a real word, but don’t you think it should be?) Which set has a better chance of winning? Well, the first set (the set containing one door) has a 1/3 chance of winning, while the second set (the set containing two doors) has a 2/3 chance of winning. Obviously, the set with two doors is more likely to contain the winning door.

Think of it this way: If you buy one lottery ticket, and I buy two lottery tickets, who has the better chance of winning? Of course, with lottery tickets neither one of us has a good chance of winning, but the person with two lottery tickets is twice as likely to win as the person with only one ticket.

When Monty asks if you would like to switch doors, what he’s really asking is, “would you like to leave the set that has a 1/3 chance of winning and move to the set that has a 2/3 chance of winning?” When framed this way, of course you’d want to switch sets!

An important thing to point out is that Monty knows in advance where the car and goats are. Since Monty can’t open the winning door, he often has no choice about which door to reveal. (If you pick door number one, and the car is behind door number two, then Monty has no choice but to reveal door number three.)

When I deliver corporate training seminars, I like to conduct an “afternoon distraction” with my students every day after lunch. One of my favorite afternoon distractions is the Monty Hall Problem. Even after explaining the solution with words and visuals, some students still don’t believe the logic actually works. Remember, I was the same way when I first heard this brain teaser a few years ago. For people that simply won’t believe it until they see it, I rewrote my initial Java application in JavaScript…. see below.

Try it out, and remember, you’re always better off switching doors. (Although, with the rising cost of gas combined with the rising cost of food, I could almost understand preferring a goat to a car!)

 

Number of wins by switching doors: 0.00% (0/0)
Number of wins by not switching doors: 0.00% (0/0)



Autobahn Bathrooms and Aeron Chairs (2)

Last August I took a two week tour of Europe. One of my favorite parts of the trip was the two days we spent in Germany. The tour included stops in St. Goar (the Rhine Valley) and Munich. Needless to say, we spent a lot of time on the Autobahn as we drove from place to place. The Autobahn is most famous for its fast drivers, but I didn’t get to experience that myself. (The tour bus I was on had its speed electronically governed, but even if that weren’t the case I doubt the laws of physics would have allowed the big beast to go much faster than 65mph anyway.) Instead of high speed driving, what I’ll always remember the most about the Autobahn are its rest stop bathrooms.

Unlike the bathrooms here in the United States, the bathrooms along the Autobahn are not free to use. In fact, it costs half a euro to answer the call of nature along the Autobahn. When I learned this, it led me to wonder if this is why so many people drive fast on their roads. Hey, if my bladder were full and I was short the requisite 50 cents I’d probably be driving 140mph too!

At first I was a little pissed off (pun intended) at having to pay to use the bathroom, but this went away once I saw how nice the facilities were. The restrooms, run by a company named Sanifair, were the cleanest and most modern public bathrooms I had ever seen. The walls were decorated with a cobalt blue tile that put my home bathroom to shame. The self cleaning toilets looked as if they had never been used. The bathroom floors were cleaner than my kitchen floors, which is especially impressive considering that I never use my kitchen. To top it off, the 50 cents it costs to use the bathrooms are refundable if you make a purchase in the rest stop restaurant. This is particularly clever since encouraging people to eat and drink is good for repeat business!

A few days after visiting Germany, the tour took us into Italy. By contrast, the bathrooms at the Italian rest stops were among the crappiest (pun intended) I have ever seen. The floors were dirty, the sinks were wet, the paper towel was often missing in action, and at one stop every single toilet seat had been removed from the stalls. On the bright side, these bathrooms were free to use.

What’s the moral of this story? German and Italian bathrooms are perfect examples that, often in life, you get what you pay for.

When running a company, it’s very important to be careful with your money. This is especially true in today’s not-so-hot economy. At my company, I do my best to watch expenses and look for ways to save money that won’t affect the happiness of my employees or the quality of our products and services. However, in some areas of the business, I’ve learned that it never pays to be cheap.

A large part of what my company does is custom software development. This makes our computers the most important tool of our trade. For this reason, I buy the top of the line computer for each new employee. The last employee I hired one month ago is now working on a MacBook Pro with 4 Gigs of Ram. The total cost of his machine, including the purchase of additional software, came to about $5,000. Sure, I could have saved a thousand dollars by purchasing a Dell, but I like to know that my developers won’t be slowed by spyware, viruses and buggy operating systems.

I also do my best to ensure that my employees are working in the most comfortable conditions. When working in the office, each of my developers sits in an extremely comfortable and ergonomic Aeron chair. On eBay, a brand new Aeron chair will cost you about $800, including shipping. This is obviously much more expensive than a “normal” office chair, but I find the price to be well worth it. The chairs are immensely more comfortable than a typical office chair, and although we’ve only owned ours for a couple of years I’m told that they will last at least a decade.

Joel Spolsky does a very good job of praising Aeron chairs in his Field Guide to Developers:

[Aeron chairs] are much more comfortable than cheap chairs. If you get the right size and adjust it properly, most people can sit in them all day long without feeling uncomfortable. The back and seat are made out of a kind of mesh that lets air flow so you don’t get sweaty. The ergonomics, especially of the newer models with lumbar support, are excellent.

They last longer than cheap chairs. We’ve been in business for six years and every Aeron is literally in mint condition: I challenge anyone to see the difference between the chairs we bought in 2000 and the chairs we bought three months ago. They easily last for ten years. The cheap chairs literally start falling apart after a matter of months. You’ll need at least four $100 chairs to last as long as an Aeron.

So the bottom line is that an Aeron only really costs $500 more over ten years, or $50 a year. One dollar per week per programmer.

A nice roll of toilet paper runs about a buck. Your programmers are probably using about one roll a week, each.

So upgrading them to an Aeron chair literally costs the same amount as you’re spending on their toilet paper, and I assure you that if you tried to bring up toilet paper in the budget committee you would be sternly told not to mess around, there were important things to discuss.

Joel was even kind enough to bring the topic full circle, back to bathrooms. Thank you, Joel. The point I’m making is that just like with European bathrooms, when it comes to office chairs you get what you pay for.

In addition to developing software, my company also provides technical training at the corporate level. As a trainer, I have the opportunity to work with software developers at a number of large business and government organizations throughout North America. I’m sad to see that many programmers in the corporate world are forced to work on old, slow computers, seated on cheap, uncomfortable chairs. I think this is being penny wise and pound foolish.

Cheap computers end up being more expensive because they slow down their well paid users. Spending an extra $1,000 on a faster computer might save a given developer twenty minutes a day in not having to wait for the compiler to return. Twenty minutes doesn’t sound like a lot until you realize that’s over 83 hours per year. If a given developer makes $50,000 per year, $2,000 of their salary is being made staring at an animated hourglass. An extra $1,000 spent on a faster computer would have paid for itself in six months.

Cheap office chairs also end up being more expensive over time because they need to be replaced more often. Replacing chairs requires time ordering them, money shipping them, time assembling them, and money having the old ones hauled away. This doesn’t even include the cost of lost productivity caused by the back pain brought on by sitting in a really bad chair.

As if all of this weren’t enough, I imagine that there’s also an opportunity cost that must be paid by being cheap with your employees. If an intelligent job candidate realizes that working for your company will require them to use sub-par equipment, seated in a sub-par chair, they will seek greener pastures.

I’m not advocating wasteful spending. On the contrary, I think that companies should be cheap where they can get away with it, and “lavish” with the pocketbook when it matters. Specifically, if it effects the happiness of customers and employees, or the quality of a product or service, then liberal spending will often pay for itself many times over. The Germans seemed to have learned this lesson. Now if somebody could please translate this page into Italian, I might be able to make a big difference in this world.

Highway Traffic and the Spacetime Continuum (1)

Have you ever thought you knew somebody reasonably well, only to be shocked by the person they become when they get behind the wheel of a car? Vehicles have the ability to turn the docile into the hostile, and the patient into the anything-but. What is it about sitting in the driver’s seat that can turn otherwise level headed people into raging madmen?

One of the elements that can fuel road rage is the relative anonymity that vehicles provide. To some, cars become like Carnaval masks, allowing them to passive-aggressively express their frustrations in ways they’d never feel comfortable with face-to-face. Others experience an adrenaline rush when they drive, reveling in the power they wield while donning their Detroit or Japanese or German made exoskeletons. With the push of a toe they can excel past lines of men and women who might otherwise have control over them in social situations. With the turn of a wheel they can cut off that jerk in the minivan who was trying make his exit. There’s no need for complex dialog while exerting your power when a simple finger will suffice!

Although road rage can happen anywhere, it’s more likely to occur in some situations over others. Obviously, the more congested traffic is the more fertile the highway becomes for road rage. The hotter the temperature outside, the hotter the tempers inside. The slower the cars are moving, the faster the hearts will be pumping.

Three weeks ago I drove from Pittsburgh to Albany to visit my grandfather. On the trip there and back I witnessed a few incidents of road rage. Through astute observation I came to realize that road rage is a phenomenon so predictable that its likelihood can be expressed with the following formula:

road rage likelihood = ((number of cars in vicinity / average speed) + temperature above 80F) * (1 + number of Hummers in sight)

Notice that this formula involves dividing by the average speed of the vehicles. This means that if the vehicles come to a complete stop the number approaches infinity!

I used to be one of those people whose blood would boil when stuck in traffic, moving at a snail’s pace. I’d play the lane switching game, hoping to improve my odds with one lateral move after another. Sometimes I’d even exit the main highway, opting for the back roads even though it often took me longer to get home that way. After all, isn’t it better to be making progress on a back road driving at 45 mph rather than 5?

Then one day, stuck on I-376 between Edgewood and Squirrel Hill, I had an epiphany. Even though my Volkswagen was moving at zero miles per hour, I realized that progress was being made. Rather than measuring my progress in terms of distance, it dawned on me that a more important measure of my progress would be one that considered spacetime. If my drive home always takes about an hour regardless of which road I take, then wouldn’t it make more sense for me to simply measure time? In other words, when I’m zipping along at 60 mph, I’m traveling through time at the rate of one minute per minute. When I’m sitting in traffic, crawling along at the breakneck speed of one lone mile per hour, I’m still traveling through time at the rate of one minute per minute!

Doc Brown.  Great Scott!With this new outlook, traffic stopped having the same anxiety inducing effects on me. Viewing my car as a forward traveling time machine, I came to realize that I should be no more frustrated by traffic congestion than I should be with miles of open road. (Or, if you’re a pessimist, you should be just as furious with empty lanes as congested ones!)

So, the next time you’re stuck on the highway, in a construction zone, moving at glacial speeds behind a suburban tank, don’t let yourself gut frustrated. Even though it doesn’t seem like you’re making progress, you really are. If you think it would help, buy yourself a Doc Brown action figure and keep it on your dashboard. Great Scott! You’re traveling through time!