Skip to content

Instantly share code, notes, and snippets.

@Heliosmaster
Created December 5, 2020 09:04
Show Gist options
  • Save Heliosmaster/5e7e42ce13097a38dbd56ca2c8856dbd to your computer and use it in GitHub Desktop.
Save Heliosmaster/5e7e42ce13097a38dbd56ca2c8856dbd to your computer and use it in GitHub Desktop.
AOC 2020 - Day 5
(require '[clojure.string :as str])
(defn binary-partition [b-string]
(let [bits (dec (count b-string))]
(->> b-string
(map-indexed (fn [i x]
(if (#{\B \R} x)
(Math/pow 2 (- bits i))
0)))
(reduce +))))
(defn seat-id [a-string]
(let [rows (drop-last 3 a-string)
cols (take-last 3 a-string)]
(+ (* 8 (binary-partition rows))
(binary-partition cols))))
(defn part-1 []
(let [data (-> (slurp (format "./inputs/day5.txt"))
(str/split-lines))]
(map seat-id data)))
(defn part-2 []
(let [seat-ids (sort (part-1))]
(loop [c (rest seat-ids)
i (first seat-ids)]
(if (= (first c) (inc i))
(recur (rest c) (first c))
(inc i)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment