restructure
This commit is contained in:
parent
fcf1891f11
commit
cfff130803
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1 +1 @@
|
|||
input
|
||||
*.txt
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
(/ "eight" "8")
|
||||
(/ "nine" "9"))})
|
||||
|
||||
(defn accum-matches [input]
|
||||
(defn match-digits [input]
|
||||
"Do a peg match character by character. Unfortunately couldn't figure out how to do overlap another way"
|
||||
(var arr @[])
|
||||
(loop [i :range [0 (length input)]]
|
||||
(let [match (first (peg/match peg input i))]
|
||||
|
@ -23,7 +24,7 @@
|
|||
arr)
|
||||
|
||||
(defn first+last [input]
|
||||
(let [m (accum-matches input)]
|
||||
(let [m (match-digits input)]
|
||||
(scan-number
|
||||
(string/join [(first m) (last m)]))))
|
||||
|
||||
|
@ -32,10 +33,10 @@
|
|||
|
||||
(start-suite)
|
||||
|
||||
(assert (deep= @["1"] (accum-matches "one")))
|
||||
(assert (deep= @["1" "2"] (accum-matches "onetwo")))
|
||||
(assert (deep= @["1" "2" "3"] (accum-matches "one2three")))
|
||||
(assert (deep= @["8" "3"] (accum-matches "eighthree")))
|
||||
(assert (deep= @["1"] (match-digits "one")))
|
||||
(assert (deep= @["1" "2"] (match-digits "onetwo")))
|
||||
(assert (deep= @["1" "2" "3"] (match-digits "one2three")))
|
||||
(assert (deep= @["8" "3"] (match-digits "eighthree")))
|
||||
|
||||
(def example
|
||||
["two1nine"
|
||||
|
@ -50,4 +51,4 @@
|
|||
|
||||
(end-suite)
|
||||
|
||||
(pp (with [f (file/open "input")] (solve (file/lines f))))
|
||||
(pp (with [f (file/open "p01.txt")] (solve (file/lines f))))
|
Loading…
Reference in a new issue