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.
23 lines
427 B
Clojure
23 lines
427 B
Clojure
(defn median [lst]
|
|
(let [cnt (count lst)
|
|
hlf (quot cnt 2)
|
|
srt (sort lst)]
|
|
(cond->> (nth srt hlf)
|
|
(even? cnt)
|
|
(+ (nth srt (dec hlf)))
|
|
:true
|
|
(#(quot % 2))
|
|
)
|
|
)
|
|
)
|
|
|
|
(->> (slurp "./in") ; "16,1,2,0,4,2,7,1,2,14"
|
|
(#(clojure.string/split % #","))
|
|
(map read-string)
|
|
(#(map (partial - (median %)) %))
|
|
(map #(Math/abs %))
|
|
(apply +)
|
|
(println)
|
|
)
|
|
|