Skip to content

Instantly share code, notes, and snippets.

@KirinDave
Created November 25, 2009 22:04
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 KirinDave/c1345f116c96f19564c4 to your computer and use it in GitHub Desktop.
Save KirinDave/c1345f116c96f19564c4 to your computer and use it in GitHub Desktop.
(defn update-ladder-for-game [{winner :winner loser :loser :as game}]
(dosync
(if (empty? @ladder)
(alter ladder into (vector winner loser))
(when-first [[_ index] (filter #(= (first %) loser) (map list @ladder (iterate inc 0)))]
(let [base1 0
stop1 (- index 1)
base2 index
modvec (-> (subvec @ladder base1 stop1) (conj winner) (into (subvec @ladder base2)))]
(alter ladder (fn (& _) modvec)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment