Created
February 20, 2010 19:18
-
-
Save oranenj/309849 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn battle | |
"returns battle results" | |
[r1 r2] | |
(nth [r1 r2 :tie] (rand-int 3))) | |
(defn battle-test | |
[r1 r2] | |
(let [battles (take 50 (repeatedly #(battle r1 r2)))] | |
(reduce (fn [[r1-wins r2-wins ties] winner] | |
(condp = (or winner :neither) | |
r1 [(inc r1-wins) r2-wins ties] | |
r2 [r1-wins (inc r2-wins) ties] | |
; else | |
[r1-wins r2-wins (inc ties)])) | |
[0 0 0] battles))) | |
(battle-test :foo :bar) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment