diff --git a/src/day01.clj b/src/day01.clj index 81afb91..ccc58c6 100644 --- a/src/day01.clj +++ b/src/day01.clj @@ -43,7 +43,73 @@ sum (reduce + 0 numbers)] (str sum))) +; +; +; +; +; +; +; +; +; +; + +; It looks like some of the digits are actually spelled out with letters: +; one, two, three, four, five, six, seven, eight, and nine also count as valid "digits". +; you now need to find the real first and last digit on each line + +; Vector of List of String,String +(def patterns ['("one" "1") '("two" "2") '("three" "3") + '("four" "4") '("five" "5") '("six" "6") + '("seven" "7") '("eight" "8") '("nine" "9")]) + +; the search tree +; a node is a list with `:n` as first element, and then +; many options list. Each list option is a (Char, Node|Leaf). +; A leaf is (:l Int) + +; Tree :: Vec of Node | Leaf +; +; Node :: (Char, Tree) +; Leaf :: String +; +; tree [ +; (\a "1") +; ] +; +; + +; adds a new word to the current search tree +(defn build-search-tree + ([] '()) + ; (Tree, String, String) -> Tree + ([prev-tree new-word new-value] + (let + ; Vec of Char + [new-letters (sequence new-word)]))) + +(defn new-leaf [value] value) +(defn new-node [char tree] (list char tree)) + +(def tree (new-node \a (new-leaf "A"))) + +; (build-search-tree "a" "1") + +; Search tree that, given a starting index `idx`, +; attempt to find a textual digit at that position. +(defn digit-at? [letters idx]) + +; Given "one3two4six" returns "13246" +; Given "eighttwothree" should include "823" somewhere, in that order +; String -> String +(defn sanitize-str [input] + (reduce (fn [acc next] (clojure.string/replace acc (first next) (last next))) input patterns)) + (defn part2 [] - (println "here will be the solution to day 1 part 2")) + (let [sanitized-lines (map sanitize-str lines) + numbers-str (map calibration-value-1 sanitized-lines) + numbers (map Integer/parseInt numbers-str) + sum (reduce + 0 numbers)] + (str sum)))