This commit is contained in:
Aleh Suprunovich 2024-12-11 08:38:41 +03:00
commit 77c00d02e8
5 changed files with 1052 additions and 0 deletions

16
.gitignore vendored Normal file
View File

@ -0,0 +1,16 @@
# ---> Clojure
pom.xml
pom.xml.asc
*.jar
*.class
/lib/
/classes/
/target/
/checkouts/
.lein-deps-sum
.lein-repl-history
.lein-plugins/
.lein-failures
.nrepl-port
.cpcache/

2
deps.edn Normal file
View File

@ -0,0 +1,2 @@
{:paths ["src" "inputs"]
:deps {org.clojure/clojure {:mvn/version "1.12.0"}}}

1000
inputs/day1 Normal file

File diff suppressed because it is too large Load Diff

6
inputs/day1.example Normal file
View File

@ -0,0 +1,6 @@
3 4
4 3
2 5
1 3
3 9
3 3

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