3 ms·
Not that this really needs another implementation, but since I already wrote it before seeing this thread... (defun monty-hall (strategy &aux (winner (random
by tc 18y ago
Not that this really needs another implementation, but since I already wrote it before seeing this thread...
(defun monty-hall (strategy &aux (winner (random 3)) (choice (random 3)))
(let ((monty (if (= winner choice)
(do ((x (random 3) (random 3)))
((/= x winner) x))
(- 3 (+ winner choice)))))
(case strategy
(:stay (= winner choice))
(:change (= winner (- 3 (+ choice monty)))))))
(looping and reporting omitted)
Incidentally, I think the code in the original article provides a good example of how code can be so verbose as to detract from understanding. Good code clarifies a problem rather than obfuscating it under the weight of useless detail.