/adventofcode16.clj Secret
Created
December 29, 2016 23:27
Star
You must be signed in to star a gist
advent of code day 16
This file contains 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
(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