Created
December 9, 2020 20:09
-
-
Save stuartstein777/eac0c817245b01b1abc2769201beefcb to your computer and use it in GitHub Desktop.
aoc 2020 day 9 part 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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