diff --git a/src/day7.clj b/src/day7.clj new file mode 100644 index 0000000..1327d06 --- /dev/null +++ b/src/day7.clj @@ -0,0 +1,65 @@ +(ns day7 + (:require [clojure.string :as string] + [helpers :refer [get-input]])) + +(def example +".......S....... +............... +.......^....... +............... +......^.^...... +............... +.....^.^.^..... +............... +....^.^...^.... +............... +...^.^...^.^... +............... +..^...^.....^.. +............... +.^.^.^.^.^...^. +...............") + + +;(def input (mapv (partial apply vector) (string/split-lines example))) +(def input (mapv (partial apply vector) (string/split-lines (get-input 7)))) + +(def line-len (count input)) +(def column-len (count (first input))) + +(def start [0 (.indexOf (apply str (first input)) "S")]) + +(def split (atom 0)) + +(defn prop [[l c]] + (if (= \^ (get-in input [l c])) + (do (swap! split inc) + [[l (dec c)] [l (inc c)]]) + [[l c]])) + +(defn propagate [beams] + (->> + beams + (map (fn [[l c]] [(inc l) c])) + (mapcat prop))) + +(loop [beams [start]] + (if (< (-> beams first first) column-len) + (recur (set (propagate beams))) + (println "Beam split" @split "times"))) + +(def memo (atom {})) + +(def timelines + (memoize + (fn [[l c]] + (cond + (or (neg? l) (neg? c) (>= c column-len) (>= l line-len)) + 1 + (= \^ (get-in input [l c])) + (+ (timelines [(inc l) (inc c)]) + (timelines [(inc l) (dec c)])) + :else + (timelines [(inc l) c]))))) + +(println "Timelines:" (timelines start))