2 (:require [clojure.string :as str]))
4 (defstruct link :height :left :right)
6 ; (def network (str/split-lines (slurp "../04-small.txt")))
7 (def network (str/split-lines (slurp "../04-lines.txt")))
9 (defn parse-link [l, h]
10 (let [endss (rest (str/split l #"\D+"))
11 ends (map #(Integer/parseInt %) endss)]
15 :right (second ends))))
17 (defn parse-network [links]
19 (fn [i l] (parse-link l i))
23 (parse-network network))
27 (str/split "abcdefghijklmnopqrstuvwxyz" #""))
29 (defn apply-link [items link]
30 (let [li (get link :left)
34 pre (subvec items 0 li)
35 mid (subvec items (inc li) ri)
36 suf (subvec items (inc ri))]
37 (into [] (concat pre (vector re) mid (vector le) suf))))
39 (defn follow [items links]
40 (reduce apply-link items links))
43 (defn lane-count [links]
44 (inc (apply max (map (fn [l] (get l :right)) links))))
46 (defn initial-heights [links]
47 (vec (replicate (lane-count links) -1)))
49 (defn pack-one [lane-heights link]
53 new-height (inc (max (nth lane-heights li)
54 (nth lane-heights ri)))]
55 (assoc lane-heights li new-height ri new-height)))
57 (defn pack [lane-heights links]
58 (reduce pack-one lane-heights links))
61 (spit "day4.out" (prn-str
62 (str/join (follow initial parsed-network))))
64 (spit "day4.out" (prn-str
67 (initial-heights parsed-network)