Skip to content

Instantly share code, notes, and snippets.

View jaihindhreddy's full-sized avatar

Jaihindh Reddy jaihindhreddy

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