Created
June 12, 2017 14:47
-
-
Save deque-blog/a218cb10363b4fff003164f4a43e0297 to your computer and use it in GitHub Desktop.
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
(defn ^:private fill-one-bucket | |
"Takes the quantity bucket-vol from a sorted-set of elements to verse | |
Returns a filled bucket and the remaining quantities" | |
[to-verse bucket-vol] | |
(let [[min-vol min-value :as min-dist] (first to-verse) | |
[max-vol max-value :as max-dist] (last to-verse) | |
fill-bucket [min-value max-value (/ min-vol bucket-vol)] | |
rest-vol (- max-vol (- bucket-vol min-vol)) | |
to-verse (disj to-verse min-dist max-dist) | |
to-verse (if (pos? rest-vol) | |
(conj to-verse [rest-vol max-value]) | |
to-verse)] | |
[fill-bucket to-verse])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment