From cf537389876cc2d118b0a2eb6fdf72b37af143b3 Mon Sep 17 00:00:00 2001 From: Adam Jeniski Date: Mon, 4 Dec 2023 01:22:00 -0500 Subject: [PATCH] simplify --- 2023/src/day04.clj | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/2023/src/day04.clj b/2023/src/day04.clj index 50fcc20..4370987 100644 --- a/2023/src/day04.clj +++ b/2023/src/day04.clj @@ -6,18 +6,15 @@ [clojure.string :as string] [core :refer [get-puzzle-input]])) -(def lines (get-puzzle-input 4)) - -(defn parse-lines [lines] - (->> lines - (map #(rest (re-find #"^Card\s*\d+: ([\s\d]+) \| ([\s\d]+)" %))) - (map (partial map #(->> (string/split % #" ") - (filter not-empty) - (map (fn [x] (Integer/parseInt x))) - (into #{})))))) +(def data (->> (get-puzzle-input 4) + (map #(rest (re-find #"^Card\s*\d+: ([\s\d]+) \| ([\s\d]+)" %))) + (map (partial map #(->> (string/split % #" ") + (filter not-empty) + (map (fn [x] (Integer/parseInt x))) + (into #{})))))) ;; part 1 -(->> (parse-lines lines) +(->> data (map (partial apply intersection)) (map count) (map #(math/pow 2 (dec %))) @@ -26,7 +23,7 @@ ;; part 2 (loop [acc 0 - data (->> (parse-lines lines) + data (->> data (map #(vector 1 (count (apply intersection %)))) (into []))] (if (not-empty data)