From 17362b34ccec35de208713610e9dd3d6d1eec024 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Wed, 8 Dec 2021 11:07:53 -0500 Subject: [PATCH] day8: make part1 concise --- day8/part1.clj | 37 ++++++++++++------------------------- 1 file changed, 12 insertions(+), 25 deletions(-) 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) + )