Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
15
Task/Monty-Hall-problem/Clojure/monty-hall-problem-1.clj
Normal file
15
Task/Monty-Hall-problem/Clojure/monty-hall-problem-1.clj
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
(ns monty-hall-problem
|
||||
(:use [clojure.contrib.seq :only (shuffle)]))
|
||||
|
||||
(defn play-game [staying]
|
||||
(let [doors (shuffle [:goat :goat :car])
|
||||
choice (rand-int 3)
|
||||
[a b] (filter #(not= choice %) (range 3))
|
||||
alternative (if (= :goat (nth doors a)) b a)]
|
||||
(= :car (nth doors (if staying choice alternative)))))
|
||||
|
||||
(defn simulate [staying times]
|
||||
(let [wins (reduce (fn [counter _] (if (play-game staying) (inc counter) counter))
|
||||
0
|
||||
(range times))]
|
||||
(str "wins " wins " times out of " times)))
|
||||
6
Task/Monty-Hall-problem/Clojure/monty-hall-problem-2.clj
Normal file
6
Task/Monty-Hall-problem/Clojure/monty-hall-problem-2.clj
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
monty-hall-problem> (println "staying:" (simulate true 1000))
|
||||
staying: wins 337 times out of 1000
|
||||
nil
|
||||
monty-hall-problem> (println "switching:" (simulate false 1000))
|
||||
switching: wins 638 times out of 1000
|
||||
nil
|
||||
Loading…
Add table
Add a link
Reference in a new issue