-
-
Save pieter-van-prooijen/0ce1fba6a8fee1f60bf9 to your computer and use it in GitHub Desktop.
Lotsa advocaat
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 containers [50 44 11 49 42 46 18 32 26 40 21 7 18 43 10 47 36 24 22 40]) | |
(defn distribute [volume containers filled] | |
(let [first-c (first containers) | |
left-over (- volume (or first-c 0))] | |
(println volume first-c filled) | |
(cond | |
(nil? first-c) nil | |
(neg? left-over) (recur volume (rest containers) filled) | |
(zero? left-over) (conj filled first-c) | |
(pos? left-over) (recur left-over (rest containers) (conj filled first-c))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment