aboutsummaryrefslogtreecommitdiffstats
path: root/day8
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2022-11-30 19:55:31 -0500
committerClyne Sullivan <clyne@bitgloo.com>2022-11-30 19:55:31 -0500
commit8d43e37df99f280377bed90284d6ac2428334804 (patch)
tree3a5042c9af29da52b4bac38fd78b3ccde77a1dbc /day8
parent66ed0b9d27850dc653abc8baa75884f3de311bfa (diff)
move 2021 days to folder; update README
Diffstat (limited to 'day8')
-rw-r--r--day8/part1.clj15
-rw-r--r--day8/part2.clj66
2 files changed, 0 insertions, 81 deletions
diff --git a/day8/part1.clj b/day8/part1.clj
deleted file mode 100644
index fe06fdf..0000000
--- a/day8/part1.clj
+++ /dev/null
@@ -1,15 +0,0 @@
-(require '[clojure.string :as str])
-
-(->> (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)
- )
-
diff --git a/day8/part2.clj b/day8/part2.clj
deleted file mode 100644
index 1ee3c08..0000000
--- a/day8/part2.clj
+++ /dev/null
@@ -1,66 +0,0 @@
-(require '[clojure.string :as str])
-(require '[clojure.set :as set])
-
-(defn find-match
- "
- Searches for digit that `has segs-left` segments remaining
- after the segments of `dig-to-cmp` are removed from the
- digits in `cnts` with `grp-to-cmp` segments.
- "
- [segs-left dig-to-cmp cnts grp-to-cmp]
- (as-> cnts $
- (filterv #(= (first %) grp-to-cmp) $)
- (filterv
- #(-> (second %)
- (str/replace (re-pattern (str/join ["[" dig-to-cmp "]"])) "")
- (count)
- (= segs-left)
- )
- $
- )
- (get-in $ [0 1])
- )
- )
-
-(defn determine-digits [line]
- (let [counts (mapv #(do [(count %) %]) (take 10 line))
- mcounts (into {} counts)]
- (as-> {} $
- (assoc $ 1 (mcounts 2)
- 4 (mcounts 4)
- 7 (mcounts 3)
- 8 (mcounts 7)
- )
- (assoc $ 3 (find-match 2 ($ 7) counts 5)
- 6 (find-match 4 ($ 7) counts 6)
- 2 (find-match 3 ($ 4) counts 5)
- 9 (find-match 2 ($ 4) counts 6)
- )
- (assoc $ 5 (find-match 2 ($ 2) counts 5))
- (assoc $ 0 (find-match 2 ($ 5) counts 6))
- )
- )
- )
-
-(println
- (reduce
- (fn [sum input]
- (let [line (as-> input $
- (str/split $ #" ")
- (mapv (comp str/join sort) $)
- )
- number (subvec line 11 15)
- decoder (set/map-invert (determine-digits line))]
- (->> number
- (map (comp str decoder))
- (str/join)
- (#(Integer/parseInt %))
- (+ sum)
- )
- )
- )
- 0
- (str/split-lines (slurp "./in"))
- )
- )
-