Probably won't get an explanatory blog post on this one today, and need to catch up to finish/submit yesterday's, but here's my Clojure solution for Day 5 (see gist.github.com/ballpointcarrot/7e...
(defn polymer-drop [[c1 c2]]
(= c1 c2) false
(or (nil? c1) (nil? c2)) false
(= (Character/toLowerCase c1) (Character/toLowerCase c2)) true
(defn shrink [input]
(loop [shrunk  chars-to-test (take 2 input) left (drop 2 input)]
(and (empty? left) (every? nil? chars-to-test)) (apply str shrunk)
(nil? (first chars-to-test)) (recur shrunk [(last chars-to-test) (first left)] (rest left))
(polymer-drop chars-to-test) (if (empty? shrunk)
(recur shrunk (take 2 left) (drop 2 left))
(recur (pop shrunk) [(last shrunk) (first left)] (rest left)))
:else (recur (conj shrunk (first chars-to-test)) [(last chars-to-test) (first left)] (rest left)))))
"Remove all instances of a character (case-insensitive)
from a string"
(apply str (remove #(or (= % (Character/toUpperCase chr)) (= % (Character/toLowerCase chr))) string)))
(map char (range (int start) (inc (int end)))))
(defn find-shortest-polymer [input-string]
(apply min (pmap #(-> input-string
(count)) (char-range \a \z))))
We’re a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.