You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
470 B
Clojure
27 lines
470 B
Clojure
(def input
|
|
(->> (slurp "./in") ; "16,1,2,0,4,2,7,1,2,14"
|
|
(#(clojure.string/split % #","))
|
|
(map read-string)
|
|
)
|
|
)
|
|
|
|
(defn median [lst]
|
|
(let [cnt (count lst)
|
|
hlf (quot cnt 2)
|
|
srt (sort lst)]
|
|
(if (odd? cnt)
|
|
(nth srt hlf)
|
|
(quot (+ (nth srt hlf) (nth srt (dec hlf))) 2)
|
|
)
|
|
)
|
|
)
|
|
|
|
(println
|
|
(->> input
|
|
(map (partial - (median input)))
|
|
(map #(if (neg? %) (- %) %))
|
|
(apply +)
|
|
)
|
|
)
|
|
|