This commit is contained in:
Aleh Suprunovich
2024-12-01 12:45:47 +03:00
commit b15a212927
5 changed files with 1052 additions and 0 deletions

28
src/day1.clj Normal file
View File

@@ -0,0 +1,28 @@
(ns day1
(:require [clojure.edn :as edn]
[clojure.string :as s]))
(def input
(->> (slurp "inputs/day1")
s/split-lines
(map #(s/split % #"\ +"))
(map #(map edn/read-string %))))
(def left-list (map first input))
(def right-list (map second input))
(def distances
(map (fn [l r] (abs (- r l)))
(sort left-list)
(sort right-list)))
(defn count-n-in-right-list [n]
(count (filter #(= n %) right-list)))
(defn similarity-for-n [n]
(* n (count-n-in-right-list n)))
(println "Total distance:" (reduce + distances))
(println "Similarity score:" (reduce + (map similarity-for-n left-list)))