Skip to content

Instantly share code, notes, and snippets.

@JanVoracek
Created February 18, 2014 03:34
Show Gist options
  • Save JanVoracek/9064233 to your computer and use it in GitHub Desktop.
Save JanVoracek/9064233 to your computer and use it in GitHub Desktop.
(ns rps.core
(:use clojure.core.match))
(defn get-rps-winner [choice-1, choice-2]
(match [choice-1, choice-2]
[choice-2, choice-1] :draw
[:rock :paper] :paper
[:paper :rock] :paper
[:rock :scissors] :rock
[:scissors :rock ] :rock
[:paper :scissors] :scissors
[:scissors :paper] :scissors
))
(defn get-winner [player-1, player-2]
(match [(get-rps-winner player-1 player-2)]
[player-1] 1
[player-2] 2
[:draw] 0))
(defn -main [& args]
(def winner (get-winner :rock :paper))
(println "Winner is player nr." winner)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment