day8: make part1 concise

master
Clyne 3 years ago
parent 85d2aae745
commit 17362b34cc

@ -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)
)

Loading…
Cancel
Save