Created
April 5, 2017 22:17
-
-
Save thieux/336068dbfe5c09d476f7eab97a3f69a9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Solution | |
| (:gen-class)) | |
| (require '[clojure.string :as str]) | |
| ; Auto-generated code below aims at helping you parse | |
| ; the standard input according to the problem statement. | |
| (defn -main [& args] | |
| (let [n (read) _ (read-line) temps (read-line)] | |
| ; n: the number of temperatures to analyse | |
| ; temps: the n temperatures expressed as integers ranging from -273 to 5526 | |
| (binding [*out* *err*] | |
| (println "DEBUG: " n temps)) | |
| (println | |
| (loop [[e & tail] (str/split temps #" ") | |
| i 0 | |
| z 0 | |
| diff 5527] | |
| (if (>= i n) | |
| z | |
| (let [t (Integer/parseInt e) | |
| p (Math/abs t)] | |
| (recur tail | |
| (inc i) | |
| (if (<= p diff) (if (= p (Math/abs z)) (max t z) t) z) | |
| (if (< p diff) p diff)))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment