mirror of
https://github.com/Ajetski/advent-of-code.git
synced 2025-09-30 09:33:19 -09:00
27 lines
517 B
Clojure
27 lines
517 B
Clojure
(ns day01
|
|
(:require
|
|
[input-manager :refer [get-input]]
|
|
[core :as c]))
|
|
|
|
(def input (->> (get-input 1)
|
|
(map #(first (c/get-match-groups #"(\d+)\s+(\d+)" %)))
|
|
(map #(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 +)))
|
|
|
|
|