Created
January 22, 2016 02:32
-
-
Save sdtsui/4026a4df7f4e08cff78c to your computer and use it in GitHub Desktop.
ex1
This file contains 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
;Working ClojureScript | |
(defn rps [p1 p2] | |
(if (== (count p1) (count p2)) "Draw!" | |
(let [win1 "Player 1 won!" win2 "Player 2 won!"] | |
(if (== p1 "scissors") (if (== p2 "paper") win1 win2) | |
(if (== p1 "rock") (if (== p2 "scissors") win1 win2) | |
(if (== p1 "paper") (if (== p2 "rock") win1 win2) | |
nil | |
) | |
) | |
) | |
) | |
) | |
) | |
;throws: | |
;java.lang.ClassCastException: | |
;java.lang.String cannot be cast to java.lang.Number at | |
;clojure.lang.Numbers.equiv (Numbers.java:206) | |
;in web repl (not in codewars env): | |
;java.lang.IllegalStateException: Attempting to call unbound fn: | |
(def rps | |
(fn [p1 p2] | |
(if (== (count p1) (count p2)) "Draw!" | |
(let [win1 "Player 1 won!" win2 "Player 2 won!"] | |
(if (== p1 "scissors") (if (== p2 "paper") win1 win2) | |
(if (== p1 "rock") (if (== p2 "scissors") win1 win2) | |
(if (== p1 "paper") (if (== p2 "rock") win1 win2) | |
nil | |
) | |
) | |
) | |
) | |
) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment