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
(defn map-vals [f m] | |
(into {} | |
(map (fn [[k v]] [k (f v)])) | |
m)) | |
(defn parse-line [s] | |
(->> (re-find #"^#(\d+) @ (\d+),(\d+): (\d+)x(\d+)" s) | |
rest | |
(map #(Integer/parseInt %)) | |
(map vector [:id :x :y :w :h]) |
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
(def input | |
"set of strings representing box IDs" | |
(clojure.string/split-lines (slurp "input.txt"))) | |
(defn twice-and-thrice [id] | |
(let [freqs (-> id frequencies vals set)] | |
[(if (freqs 2) 1 0) | |
(if (freqs 3) 1 0)])) | |
(defn elem-diff [a b] |
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
(def input (->> (slurp "input.txt") | |
clojure.string/split-lines | |
(map #(Integer. %)))) | |
(def part-1 (apply + input)) | |
(def part-2 (->> (cycle input) | |
(reductions + 0) | |
(reduce (fn [seen? v] | |
(if (seen? v) | |
(reduced v) |