Skip to content

Instantly share code, notes, and snippets.

@timmc
Created December 30, 2015 21:42
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 timmc/35c969e97ac1c5e7f72f to your computer and use it in GitHub Desktop.
Save timmc/35c969e97ac1c5e7f72f to your computer and use it in GitHub Desktop.
(defn bucket-nums
[width start xs]
(loop [buckets []
stream xs
threshold (+ start width)]
(if (empty? stream)
buckets
(let [[under beyond] (split-with #(< % threshold) stream)]
(recur (conj buckets under)
beyond
(+ threshold width))))))
(bucket-nums 1000 0 [1 35 456 2005 3045 3987])
;;= [(1 35 456) () (2005) (3045 3987)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment