Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defn win? [hold-the-door?]
- (let [doors (set (range 3))
- $$-door (rand-int 3)
- contestant-init-sel (rand-int 3)
- monty-sel (-> doors
- (disj contestant-init-sel $$-door)
- first)
- final-sel (if hold-the-door?
- contestant-init-sel
- (-> doors
- (disj contestant-init-sel monty-sel)
- first))]
- (= final-sel $$-door)))
- (defn win-stats [hold-the-door? n]
- (let [freqs (frequencies
- (for [_ (range n)]
- (win? hold-the-door?)))
- wins (get freqs true 0)
- losses (get freqs false 0)]
- {:win% (-> (/ wins (+ wins losses))
- (* 100)
- float)
- :wins wins
- :losses losses}))
- (def holdin-dat-door (partial win-stats true))
- (def i-prefer-another-door (partial win-stats false))
- (comment
- (time (i-prefer-another-door 1e6))
- "Elapsed time: 1843.44821 msecs"
- {:win% 66.6149, :wins 666149, :losses 333851}
- (time (holdin-dat-door 1e6))
- "Elapsed time: 1415.997953 msecs"
- {:win% 33.4201, :wins 334201, :losses 665799})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement