feat: work on day 1 part 2
This commit is contained in:
parent
e0c144c73d
commit
1330e091a2
@ -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)))
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user