(ns edition2022.day1
  (:require [clojure.string :as str]))
;https://adventofcode.com/2022/day/1

(defn read-input []
  (let [input-str (slurp "resources/day1.in")
        input (str/split-lines input-str)]
    (loop [in input
           result []]
      (if (empty? in)
        result
        (recur (rest (drop-while #(not= "" %) in)) (conj result (map #(Integer/parseInt %) (take-while #(not= "" %) in))))))))

(defn calculate-calories [backpack]
  (apply + backpack))

(defn find-max-calories [backpacks]
  (apply max (map calculate-calories backpacks)))

(defn top-3-calories [backpacks]
  (->> (map calculate-calories backpacks)
       (sort)
       (take-last 3)
       (apply +)))

(comment
  (calculate-calories [1 2 3 4])
  (find-max-calories [[1 2] [3 4]])
  (top-3-calories [[1 2] [3 4] [5 6] [7 8]])
  (read-input)
  (find-max-calories (read-input))
  (top-3-calories (read-input)))