Skip to content

Instantly share code, notes, and snippets.

@futurepaul
Last active August 29, 2015 14:13
Show Gist options
  • Save futurepaul/212c8b7b3fdda16d5d24 to your computer and use it in GitHub Desktop.
Save futurepaul/212c8b7b3fdda16d5d24 to your computer and use it in GitHub Desktop.
rock paper scissors
(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