Skip to content

Instantly share code, notes, and snippets.

@thieux
Created April 5, 2017 22:17
Show Gist options
  • Select an option

  • Save thieux/336068dbfe5c09d476f7eab97a3f69a9 to your computer and use it in GitHub Desktop.

Select an option

Save thieux/336068dbfe5c09d476f7eab97a3f69a9 to your computer and use it in GitHub Desktop.
(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