Skip to content

Instantly share code, notes, and snippets.

@nikolavojicic
Created December 11, 2023 11:23
Show Gist options
  • Save nikolavojicic/8591d9bb1ffead8cdc94e3a847e8c610 to your computer and use it in GitHub Desktop.
Save nikolavojicic/8591d9bb1ffead8cdc94e3a847e8c610 to your computer and use it in GitHub Desktop.
(def break (System/getProperty "line.separator"))
(def moves
{:p {:desc "PAPER" :beats :r}
:r {:desc "ROCK" :beats :s}
:s {:desc "SCISSORS" :beats :p}})
(defn vs [m1 m2]
(cond
(= m1 m2) "IT'S A DRAW"
(= (:beats (m1 moves)) m2) "YOU WIN"
:else "YOU LOOSE"))
(defn -main [& args]
(println "(P)APER, (R)OCK, (S)CISSORS OR (E)XIT?")
(let [you (keyword (.toLowerCase (read-line)))
bot (rand-nth (keys moves))]
(when (not= :e you)
(println
(str "YOU :: " (:desc (you moves) "INVALID") break
"BOT :: " (:desc (bot moves)) break
"-----> " (vs you bot) break
(apply str (repeat 38 "-"))))
(recur args))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment