Created
December 14, 2020 15:25
-
-
Save leetwinski/7c1e4ff328a5a7d6a82ca837067e0aa7 to your computer and use it in GitHub Desktop.
advent of code 2020 / 5
This file contains hidden or 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 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