Skip to content

Instantly share code, notes, and snippets.

@jamtur01
Created November 25, 2024 16:58
Show Gist options
  • Save jamtur01/674c681088414f2d01292cd5ae971e02 to your computer and use it in GitHub Desktop.
Save jamtur01/674c681088414f2d01292cd5ae971e02 to your computer and use it in GitHub Desktop.
(defn meal-prep
"Calculate minimum hours needed to cook meals given prep times in minutes.
Each meal must be cooked for its full duration (rounded up to nearest hour).
Up to 2 meals can be cooked simultaneously.
Args:
prep-times - Collection of meal preparation times in minutes
Returns:
Minimum hours needed to cook all meals"
[prep-times]
{:pre [(seq prep-times)
(every? pos? prep-times)]}
(let [hours (->> prep-times
(map #(Math/ceil (/ % 60.0)))
(into []))
total-slots (reduce + hours)
max-single-meal (reduce max hours)]
(int (max max-single-meal
(Math/ceil (/ total-slots 2))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment