Skip to content

Instantly share code, notes, and snippets.

@leetwinski
Created December 14, 2020 15:25
Show Gist options
  • Save leetwinski/7c1e4ff328a5a7d6a82ca837067e0aa7 to your computer and use it in GitHub Desktop.
Save leetwinski/7c1e4ff328a5a7d6a82ca837067e0aa7 to your computer and use it in GitHub Desktop.
advent of code 2020 / 5
(defn locator [r n]
(fn [in]
(->> (iterate #(/ % 2) (/ n 2))
(map vector in)
(keep (fn [[ch n]] (when (#{r} ch) n)))
(apply +))))
(let [get-row (locator \B 128)
get-col (locator \R 8)]
(defn get-seat [in]
(let [[r c] (split-at 7 in)]
(+ (* 8 (get-row r))
(get-col c)))))
(let [seats (into (sorted-set) (map get-seat data-5))
rng (apply range ((juxt first last) seats))]
[(first (remove seats rng)) (last seats)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment