Hi, I started learning clojure for a few months and this is what I have for the problem, and I find it running very slow if exceeding 100k trials, maybe it's because of using set? Any feedbacks will be appreciated. thx
(require '[clojure.set :as set]) (def doors #{:a :b :c}) (defn rand-nth-set [s] (conj #{} (rand-nth (seq s)))) (defn play ([] (play nil)) ([switch?] (let [prize-door (rand-nth-set doors) picked-door (rand-nth-set doors) empty-doors (set/difference doors prize-door) opened-door (rand-nth-set (set/difference empty-doors picked-door)) picked-door (if switch? (set/difference doors opened-door picked-door) picked-door)] (= picked-door prize-door)))) (count (remove #(false? %) (repeatedly 10000 #(play true)))) (count (remove #(false? %) (repeatedly 10000 #(play false)))) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en