Skip to content

Instantly share code, notes, and snippets.

@tosh
Created December 29, 2016 23:27
Show Gist options
  • Save tosh/805a75755bdb393ec7f4710cf8d032ed to your computer and use it in GitHub Desktop.
Save tosh/805a75755bdb393ec7f4710cf8d032ed to your computer and use it in GitHub Desktop.
advent of code day 16
(ns advent-of-code.day16)
(def input "11101000110010100")
(defn parse [input]
(into [] (map #(if (= % \1) true false) input)))
; ppmap from brave clojure
(defn ppmap
"Partitioned pmap, for grouping map ops together to make parallel
overhead worthwhile"
[grain-size f & colls]
(apply concat
(apply pmap
(fn [& pgroups] (doall (apply map f pgroups)))
(map (partial partition-all grain-size) colls))))
(defn expand [seed size]
(if (< (count seed) size)
(recur (into [] (concat seed [false] (ppmap 1000 not (rseq seed)))) size)
(take size seed)))
(defn checksum [bools]
(if (even? (count bools))
(recur (into [] (ppmap 1000 #(= (first %) (second %)) (partition 2 bools))))
bools))
(defn part1 []
(count
(checksum
(expand (parse input) 272))))
(defn part2 []
(checksum
(expand (parse input) 35651584)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment