Skip to content

Instantly share code, notes, and snippets.

@alandipert
Created January 18, 2012 05:33
Show Gist options
  • Save alandipert/1631183 to your computer and use it in GitHub Desktop.
Save alandipert/1631183 to your computer and use it in GitHub Desktop.
Rock paper scissor
(def dominates
{:rock :paper
:scissors :rock
:paper :scissors})
(defn winner [p1-choice p2-choice]
(first (keep (comp #{p1-choice p2-choice} dominates) [p1-choice p2-choice])))
;;; vs. the solution from labrepl
;;; https://github.com/relevance/labrepl/blob/master/src/solutions/rock_paper_scissors.clj
;; (defn winner [p1-choice p2-choice]
;; (cond
;; (= p1-choice p2-choice) nil
;; (= (dominates p1-choice) p2-choice) p2-choice
;; :else p1-choice))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment