Last active
October 4, 2015 13:31
-
-
Save isqad/1ad299c8c2d41b850fc7 to your computer and use it in GitHub Desktop.
CodinGame - my learning #clojure lang
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
(ns Player | |
(:gen-class)) | |
; Auto-generated code below aims at helping you parse | |
; the standard input according to the problem statement. | |
; --- | |
; Hint: You can use the debug stream to print initialTX and initialTY, if Thor seems not follow your orders. | |
(defn -main [& args] | |
(let [lightX (read) lightY (read) initialTX (read) initialTY (read)] | |
; lightX: the X position of the light of power | |
; lightY: the Y position of the light of power | |
; initialTX: Thor's starting X position | |
; initialTY: Thor's starting Y position | |
(let [remainingTurns (read)] | |
(loop [thorX initialTX thorY initialTY] | |
(when (and (= thorY lightY) (= thorX lightX)) | |
(println "") | |
(def x thorX) | |
(def y thorY)) | |
(when (and (< thorY lightY) (< thorX lightX)) | |
(println "SE") | |
(def x (inc thorX)) | |
(def y (inc thorY))) | |
(when (and (= thorY lightY) (< thorX lightX)) | |
(println "E") | |
(def x (inc thorX)) | |
(def y thorY)) | |
(when (and (= thorY lightY) (> thorX lightX)) | |
(println "W") | |
(def x (dec thorX)) | |
(def y thorY)) | |
(when (and (< thorY lightY) (= thorX lightX)) | |
(println "S") | |
(def x thorX) | |
(def y (inc thorY))) | |
(when (and (> thorY lightY) (= thorX lightX)) | |
(println "N") | |
(def x thorX) | |
(def y (dec thorY))) | |
(when (and (< thorY lightY) (> thorX lightX)) | |
(println "SW") | |
(def x (dec thorX)) | |
(def y (inc thorY))) | |
(when (and (> thorY lightY) (> thorX lightX)) | |
(println "NW") | |
(def x (dec thorX)) | |
(def y (dec thorY))) | |
(when (and (> thorY lightY) (< thorX lightX)) | |
(println "NE") | |
(def x (inc thorX)) | |
(def y (dec thorY))) | |
(recur x y))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment