mirror of
https://github.com/Ajetski/advent-of-code.git
synced 2025-11-27 11:32:45 -10:00
rewrite day 1 with franz
This commit is contained in:
parent
0492cb1155
commit
66c7ee02d4
@ -1,26 +1,24 @@
|
|||||||
(ns day01
|
(ns day01
|
||||||
(:require
|
(:require input-manager))
|
||||||
[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
|
;; part 1
|
||||||
|
(defn every-other [coll]
|
||||||
|
(take-nth 2 coll))
|
||||||
|
|
||||||
|
(def input (->> (input-manager/get-input-raw 2024 1)
|
||||||
|
(re-seq #"\d+")
|
||||||
|
(map parse-long)
|
||||||
|
((juxt every-other (comp every-other rest)))))
|
||||||
|
|
||||||
(->> input
|
(->> input
|
||||||
(map sort)
|
(map sort)
|
||||||
(apply zipmap)
|
(apply map (comp abs -))
|
||||||
(map #(abs (apply - %)))
|
(apply +))
|
||||||
(reduce +))
|
|
||||||
|
|
||||||
;; part 2
|
;; part 2
|
||||||
(let [[a b] input
|
(let [[left-col right-col] input
|
||||||
freqs (frequencies b)]
|
freqs (frequencies right-col)]
|
||||||
(->> a
|
(->> left-col
|
||||||
(map #(* (or (freqs %) 0) %))
|
(map #(* (or (freqs %) 0) %))
|
||||||
(reduce +)))
|
(reduce +)))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user