mirror of
https://github.com/Ajetski/advent-of-code.git
synced 2025-09-30 13:03:19 -09:00
28 lines
586 B
Clojure
28 lines
586 B
Clojure
(ns day01
|
|
(:require
|
|
[input-manager :refer [get-input]]
|
|
[core :as c]))
|
|
|
|
(def input (->> (get-input 1)
|
|
(map (c/compose #(re-seq #"(\d+)\s+(\d+)" %)
|
|
first rest ; only get match groups
|
|
#(mapv parse-long %)))
|
|
(into {})
|
|
((juxt keys vals))))
|
|
|
|
;; part 1
|
|
(->> input
|
|
(map sort)
|
|
(apply zipmap)
|
|
(map #(abs (apply - %)))
|
|
(reduce +))
|
|
|
|
;; part 2
|
|
(let [[a b] input
|
|
freqs (frequencies b)]
|
|
(->> a
|
|
(map #(* (or (freqs %) 0) %))
|
|
(reduce +)))
|
|
|
|
|