Skip to content

Instantly share code, notes, and snippets.

@matt-y
Created May 16, 2023 18:57
Show Gist options
  • Save matt-y/e61efd18cce32cf85fd7248bea392ab7 to your computer and use it in GitHub Desktop.
Save matt-y/e61efd18cce32cf85fd7248bea392ab7 to your computer and use it in GitHub Desktop.
2022p1
(def sample-1 (file/input-lines (input-gen "sample-1.dat")))
;; sample-1.dat raw:
;; 1000
;; 2000
;; 3000
;; 4000
;; 5000
;; 6000
;; 7000
;; 8000
;; 9000
;; 10000
(def group-by-xf
;; This partitions and filters out blank groups ("") which
;; correspond to the empty lines in the input, and also parses the number strings
(comp (partition-by (fn [s] (not (= "" s))))
(filter (fn [g] (not (= "" (first g)))))
(map (fn [g]
(map (fn [n] (Integer/parseInt n)) g)))))
(defn wrangle-input [input-lines]
(into '() group-by-xf input-lines))
(defn greatest-group-sum [groups]
(first (sort > (map (fn [g]
(reduce + 0 g))
groups))))
(comment
(let [in (wrangle-input sample-1)]
(greatest-group-sum in))
,)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment