do 2017 day 9
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
(ns day09
|
||||
(:require [clojure.string :as str]
|
||||
core
|
||||
input-manager))
|
||||
|
||||
(def input (input-manager/get-input-raw 2017 9))
|
||||
|
||||
(defn sum-recursive-depths [s sum idx depth]
|
||||
(if (>= idx (count s))
|
||||
sum
|
||||
(condp = (.charAt s idx)
|
||||
\, (recur s sum (inc idx) depth)
|
||||
\{ (recur s
|
||||
(+ sum depth)
|
||||
(inc idx)
|
||||
(inc depth))
|
||||
\} (recur s
|
||||
sum
|
||||
(inc idx)
|
||||
(max (dec depth) 0)))))
|
||||
|
||||
(defn exlam-canceler [s] (str/replace s #"!." ""))
|
||||
(def angle-bracket-regex #"<[^>]*>")
|
||||
|
||||
(-> input
|
||||
exlam-canceler
|
||||
(str/replace angle-bracket-regex "")
|
||||
(sum-recursive-depths 0 0 1))
|
||||
|
||||
(->> input
|
||||
exlam-canceler
|
||||
(re-seq angle-bracket-regex)
|
||||
(map #(- (count %) 2))
|
||||
(reduce +))
|
||||
Reference in New Issue
Block a user