Skip to content

Instantly share code, notes, and snippets.

@tosh
Created December 29, 2016 23:27
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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