mirror of
https://github.com/Ajetski/advent-of-code.git
synced 2025-09-30 11:23:17 -09:00
day 2
This commit is contained in:
parent
1f5cc1cf5e
commit
3e35bcad4a
1000
2024/input/2.txt
Normal file
1000
2024/input/2.txt
Normal file
File diff suppressed because it is too large
Load Diff
@ -2,15 +2,34 @@
|
||||
(:require
|
||||
[input-manager :refer [get-input]]
|
||||
[core :as c]))
|
||||
(do
|
||||
(def input
|
||||
(->> (get-input 1)
|
||||
(map identity)))
|
||||
input)
|
||||
|
||||
(def input (->> (get-input 2)
|
||||
(map c/split-whitespace)
|
||||
(map #(mapv parse-long %))))
|
||||
|
||||
(defn get-diffs [coll]
|
||||
(->> (map vector coll (rest coll))
|
||||
(mapv #(apply - %))))
|
||||
|
||||
(defn small-diffs? [diffs]
|
||||
(or (every? #(<= 1 % 3) diffs)
|
||||
(every? #(<= -3 % -1) diffs)))
|
||||
|
||||
(defn remove-at-idx [v idx]
|
||||
(concat (subvec v 0 idx) (subvec v (inc idx))))
|
||||
|
||||
;; part 1
|
||||
(->> input)
|
||||
(->> input
|
||||
(mapv get-diffs)
|
||||
(filterv small-diffs?)
|
||||
count)
|
||||
|
||||
;; part 2
|
||||
;; (->> input)
|
||||
(->> input
|
||||
(map (fn [coll]
|
||||
(map #(remove-at-idx coll %)
|
||||
(range (count coll)))))
|
||||
(map #(map get-diffs %))
|
||||
(filter #(some small-diffs? %))
|
||||
count)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user