Monday, January 02, 2012

Monty Hall problem in Clojure

~/src/gh/goat.clj.html
; Monty Hall problem in Clojure

(defn pick-first-guess [doors]
  (first doors)
)

(defn change-guess [doors]
  (if (= :goat (second doors)) (last doors)
    (second doors))
)

(def samples (map shuffle (repeat 1000 [:goat :goat :car])))

(count (filter #(= % :car) (map pick-first-guess samples)))
(count (filter #(= % :car) (map change-guess samples)))

0 Kommentare: