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.

Revisions

  1. leetwinski created this gist Dec 14, 2020.
    17 changes: 17 additions & 0 deletions main.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    (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)])