From: Clyne Sullivan Date: Wed, 8 Dec 2021 16:07:53 +0000 (-0500) Subject: day8: make part1 concise X-Git-Url: https://code.bitgloo.com/?a=commitdiff_plain;h=17362b34ccec35de208713610e9dd3d6d1eec024;p=clyne%2Fadvent-of-code.git day8: make part1 concise --- diff --git a/day8/part1.clj b/day8/part1.clj index 6c8cd0f..fe06fdf 100644 --- a/day8/part1.clj +++ b/day8/part1.clj @@ -1,28 +1,15 @@ (require '[clojure.string :as str]) -(loop [sum 0] - (let [line (read-line)] - (if (empty? line) - (println sum) - (recur - (+ - sum - (reduce - #(let [c (count %2)] - (if (or (= 2 c) (= 3 c) (= 4 c) (= 7 c)) - (inc %1) - %1 - ) - ) - 0 - (subvec - (mapv (comp str/join sort) (str/split line #" ")) - 11 15 - ) - ) - ) - ) - ) - ) - ) +(->> (str/split-lines (slurp "./in")) + (map + (fn [line] + (as-> line $ + (str/split $ #" ") + (subvec $ 11 15) + (filter #(.contains [2 3 4 7] (count %)) $) + (count $) + ))) + (apply +) + (println) + )