mirror of
https://github.com/Ajetski/advent-of-code.git
synced 2025-09-30 09:33:19 -09:00
simplify
This commit is contained in:
parent
b38a9393d3
commit
cf53738987
@ -6,18 +6,15 @@
|
|||||||
[clojure.string :as string]
|
[clojure.string :as string]
|
||||||
[core :refer [get-puzzle-input]]))
|
[core :refer [get-puzzle-input]]))
|
||||||
|
|
||||||
(def lines (get-puzzle-input 4))
|
(def data (->> (get-puzzle-input 4)
|
||||||
|
(map #(rest (re-find #"^Card\s*\d+: ([\s\d]+) \| ([\s\d]+)" %)))
|
||||||
(defn parse-lines [lines]
|
(map (partial map #(->> (string/split % #" ")
|
||||||
(->> lines
|
(filter not-empty)
|
||||||
(map #(rest (re-find #"^Card\s*\d+: ([\s\d]+) \| ([\s\d]+)" %)))
|
(map (fn [x] (Integer/parseInt x)))
|
||||||
(map (partial map #(->> (string/split % #" ")
|
(into #{}))))))
|
||||||
(filter not-empty)
|
|
||||||
(map (fn [x] (Integer/parseInt x)))
|
|
||||||
(into #{}))))))
|
|
||||||
|
|
||||||
;; part 1
|
;; part 1
|
||||||
(->> (parse-lines lines)
|
(->> data
|
||||||
(map (partial apply intersection))
|
(map (partial apply intersection))
|
||||||
(map count)
|
(map count)
|
||||||
(map #(math/pow 2 (dec %)))
|
(map #(math/pow 2 (dec %)))
|
||||||
@ -26,7 +23,7 @@
|
|||||||
|
|
||||||
;; part 2
|
;; part 2
|
||||||
(loop [acc 0
|
(loop [acc 0
|
||||||
data (->> (parse-lines lines)
|
data (->> data
|
||||||
(map #(vector 1 (count (apply intersection %))))
|
(map #(vector 1 (count (apply intersection %))))
|
||||||
(into []))]
|
(into []))]
|
||||||
(if (not-empty data)
|
(if (not-empty data)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user