-
-
Save matt-y/e61efd18cce32cf85fd7248bea392ab7 to your computer and use it in GitHub Desktop.
2022p1
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
(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