Skip to content

Instantly share code, notes, and snippets.

@tiagodavi
Created July 25, 2016 17:38
Show Gist options
  • Save tiagodavi/1747bd83b144a1aecd32bb14800b2750 to your computer and use it in GitHub Desktop.
Save tiagodavi/1747bd83b144a1aecd32bb14800b2750 to your computer and use it in GitHub Desktop.
Compare the Triplets.clj
(defn to-int [x]
(Integer/parseInt x))
(defn string-to-vector [x]
(clojure.string/split x #" "))
(def alice-points (atom 0))
(def bob-points (atom 0))
(defn counter [points]
(swap! points inc))
(defn calculate [a b]
(let [x (to-int a)
y (to-int b)]
(cond
(> x y) (counter alice-points)
(> y x) (counter bob-points)
:else :nobody
)) {:alice @alice-points :bob @bob-points})
(def alice (string-to-vector (read-line)))
(def bob (string-to-vector (read-line)))
(def result (last (map calculate alice bob)))
(println (result :alice) (result :bob))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment