(ns five.core
(:require [clojure.java.io :as io]
[clojure.string :as str]))
(def passes (-> "input.dat"
io/resource
slurp
str/split-lines))
(defn pass->col-row [pass]
(let [binary-str (-> pass (str/replace #"[FL]" "0")
(str/replace #"[BR]" "1"))
binary-row (subs binary-str 0 7)
binary-col (subs binary-str 7)]
(map #(Integer/parseInt % 2) (list binary-row binary-col))))
(def col-row-pairs (map pass->col-row passes))
(def seat-ids (map #(+ (* (first %) 8) (second %)) col-row-pairs))
(def highest (apply max seat-ids))
(def sorted (sort seat-ids))
(def sorted-is-weird (map-indexed (fn [i id] (- id 100 i)) sorted))
(def first-weird-index (.indexOf (apply str sorted-is-weird) "1"))
(def missing-id (- (nth sorted first-weird-index) 1))