2008-10-26

Monty Hall Paradox

The example of how tackling a problem in a "hacker's hat" can make a paradox trivial to understand.
(defun monty-hall (n)
"Returns a ratio of success rate to failure rate, if we follow
the strategy of always switching the initially selected door in
the Monty Hall Problem"
(let ((succ 0.0)
(fail 0.0))
(dotimes (i n)
(let ((choice (random 3))
(prize (random 3)))
(if (= choice prize)
(incf fail) ; we've chosen the right door, but will need to switch
(incf succ)))) ; we've chosen the wrong door and after switching -- the right
(/ succ fail)))

And the statistics:
CL-USER> (monty-hall 100)
1.5641025
CL-USER> (monty-hall 1000)
1.6455027
CL-USER> (monty-hall 10000)
1.9958059
CL-USER> (monty-hall 100000)
2.0147724
CL-USER> (monty-hall 1000000)
1.9966408
CL-USER> (monty-hall 10000000)
1.9986455

No comments: