Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Created June 12, 2017 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deque-blog/a218cb10363b4fff003164f4a43e0297 to your computer and use it in GitHub Desktop.
Save deque-blog/a218cb10363b4fff003164f4a43e0297 to your computer and use it in GitHub Desktop.
(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