Skip to content

Instantly share code, notes, and snippets.

@paomian
Created September 13, 2014 12:00
Show Gist options
  • Save paomian/f7b3a512af2fc5badd38 to your computer and use it in GitHub Desktop.
Save paomian/f7b3a512af2fc5badd38 to your computer and use it in GitHub Desktop.
clojure quick sort
(defn nom [n] (take n (repeatedly #(rand-int n))))
(defn sort-parts
[work]
(lazy-seq
(loop [[part & parts] work]
(if-let [[pivot & xs] (seq part)]
(let [smaller? #(< % pivot)]
(recur (list*
(filter smaller? xs)
pivot
(remove smaller? xs)
parts)))
(when-let [[x & parts] parts]
(cons x (sort-parts parts)))))))
(defn qsort [xs]
(sort-parts (list xs)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment