Created
January 18, 2012 05:33
-
-
Save alandipert/1631183 to your computer and use it in GitHub Desktop.
Rock paper scissor
This file contains hidden or 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
(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