Skip to content

Instantly share code, notes, and snippets.

@featheredtoast
Created December 15, 2017 06:13
Show Gist options
  • Save featheredtoast/f02dc22ed598cf228319b480015464fa to your computer and use it in GitHub Desktop.
Save featheredtoast/f02dc22ed598cf228319b480015464fa to your computer and use it in GitHub Desktop.
advent 2017 day 1
(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