Skip to content

Instantly share code, notes, and snippets.

@andredublin
Last active December 3, 2022 03:14
Show Gist options
  • Save andredublin/9248c6c9348261869d3e34023835e281 to your computer and use it in GitHub Desktop.
Save andredublin/9248c6c9348261869d3e34023835e281 to your computer and use it in GitHub Desktop.
aoc 2022
(defn parse-int [s] (Integer/parseInt s))
(defn chunk-lines-by-blank
"Given a seq of lines, assumes that chunks of lines are separated by a blank line
(a line containing only white space) and returns a seq of those chunks
(with each chunk being its own seq of lines)"
[lines]
(->> lines
(partition-by clojure.string/blank?)
(filter (fn [c]
(not (and
(= (count c) 1)
(= (first c) "")))))))
(defn process-part-one [input]
(->> input
(clojure.string/split-lines)
(chunk-lines-by-blank)
(map (fn [chunk]
(map parse-int chunk)))
(map (fn [chunk]
(reduce + chunk)))
(apply max)
(str)))
(defn process-part-two [input]
(->> input
(clojure.string/split-lines)
(chunk-lines-by-blank)
(map (fn [chunk]
(map parse-int chunk)))
(map (fn [chunk]
(reduce + chunk)))
(sort >)
(take 3)
(reduce +)
(str)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment