Last active
August 29, 2015 14:13
-
-
Save futurepaul/212c8b7b3fdda16d5d24 to your computer and use it in GitHub Desktop.
rock paper scissors
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 rps-rules {"rock" "scissors", | |
"paper" "rock", | |
"scissors" "paper"}) | |
(defn rps-random [] | |
(let [comp-choice (int (* (rand) 3))] | |
((into [] (keys rps-rules)) comp-choice))) | |
(defn rps-winner [choice comp-choice] | |
(if (= (rps-rules choice) comp-choice) | |
(print "You won!") | |
(print "You lost!"))) | |
(defn rps [choice] | |
(let [comp-choice (rps-random)] | |
(if (= comp-choice choice) | |
(println "A tie!") | |
(println | |
(str (rps-winner choice comp-choice) " The computer chose " comp-choice))))) | |
(rps "paper") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment