Created
December 15, 2017 06:13
-
-
Save featheredtoast/f02dc22ed598cf228319b480015464fa to your computer and use it in GitHub Desktop.
advent 2017 day 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn double-up [coll] | |
(->> (repeat coll) | |
(take 2) | |
(apply concat))) | |
(defn split-out-by-parts [length coll] | |
(->> (partition (inc (/ (count coll) 4)) 1 coll ) | |
(take length) | |
(map (juxt first last)))) | |
(defn every-same-pred [candidate] | |
(apply = candidate)) | |
(defn every-same-pred-filter [coll] | |
(filter every-same-pred coll)) | |
(defn prepare-coll [str] | |
(let [length (if even? (count str) (count str))] | |
(->> (mapv #(Integer/parseInt %) (clojure.string/split str #"")) | |
double-up | |
((partial split-out-by-parts length)) | |
every-same-pred-filter | |
(map first) | |
(reduce +)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment