advent-of-code/2024/src/day01.clj
2024-12-01 12:33:54 -05:00

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 +)))