Skip to content

Instantly share code, notes, and snippets.

Avatar

Jaihindh Reddy jaihindhreddy

  • Hyderabad, Telangana, India
View GitHub Profile
@jaihindhreddy
jaihindhreddy / advent-of-code-2018-02.clj
Last active Dec 16, 2018
Advent of Code 2018 Day 2
View advent-of-code-2018-02.clj
(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]
@jaihindhreddy
jaihindhreddy / advent-of-code-2018-03.clj
Last active Dec 16, 2018
Advent of Code 2018 Day 3
View advent-of-code-2018-03.clj
(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])
View advent-of-code-2018-01.clj
(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)