Skip to content

Instantly share code, notes, and snippets.

@oranenj
Created February 20, 2010 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oranenj/309849 to your computer and use it in GitHub Desktop.
Save oranenj/309849 to your computer and use it in GitHub Desktop.
(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