Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: