Skip to content

Instantly share code, notes, and snippets.

@stuartstein777
Created December 9, 2020 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stuartstein777/eac0c817245b01b1abc2769201beefcb to your computer and use it in GitHub Desktop.
Save stuartstein777/eac0c817245b01b1abc2769201beefcb to your computer and use it in GitHub Desktop.
aoc 2020 day 9 part 2
(defn parse-input []
(->> (slurp "puzzle-inputs/2020/day9")
(str/split-lines)
(map #(Long/parseLong %))))
(defn reduce-window [part]
(let [min (apply min part)
max (apply max part)]
[(+ min max) (reduce + 0 part)]))
(time (let [invalid 14144619
input (parse-input)]
(loop [i 4]
(let [sums (->> (partition i 1 input)
(map reduce-window))
found? (for [xs sums
:when (= invalid (second xs))]
(first xs))]
(if (seq found?)
(first found?)
(recur (inc i)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment