aboutsummaryrefslogtreecommitdiffstats
path: root/day7/part1.clj
blob: 03c2aa655208b7afa8db78d9bd8a062fccfa05f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
(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)
     )