Created
December 3, 2014 03:15
-
-
Save kliph/e85046d788362c1ce0bb to your computer and use it in GitHub Desktop.
Sampling without replacement in Clojure
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 sample-without-replacement [coll] | |
"Returns a tuple in which the first value is the sample and the | |
second is a collection of the left over values. Does not preserve | |
the order of the input collection." | |
(let [shuffled (shuffle coll) | |
sample (last shuffled) | |
rest (pop shuffled)] | |
[sample rest])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment