on the unexpected benefits of algorithms

I was recently talking to one of the volunteers at work, discussing the well-known exercise in probability theory where there’s a game show with three doors. Behind each door is a prize, one of which is very valuable while the other two are worthless. The contestant has to pick one door, then one of the other doors is opened to reveal a worthless prize. The contestant then has the opportunity to change his/her mind and choose the remaining door. What is the contestant’s best strategy?

The answer, perhaps counter-intuitively, is: switch and pick the remaining door.  Precisely because it seemed counter-intuitive, I decided to write a simple programme to show the results of a large number of iterations, but, while planning the code, I proved to my own satisfaction that changing your mind is the better strategy. So I had the strange experience of learning through preparing to code, with the outcome that I didn’t need to write the code!

In effect there are only two courses:

  • either the contestant picks the door with the valuable prize (a 1 in 3 chance), in which case it would be unwise to switch; or:
  • the contestant picks one of two doors with the worthless prize,  (a 2 in 3 chance), in which case it would be wise to switch.

Since the latter course is more likely, the better strategy is to switch. QED. The revelation of the prize behind another door is merely a distraction.

Conclusion: the discipline of writing an algorithm helps to think logically about the problem.

Monday, February 9th, 2015 coding

Leave a Reply