Created
November 6, 2012 02:21
-
-
Save bnyeggen/4022149 to your computer and use it in GitHub Desktop.
Rational bozo sort
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 rational-bozo-sort | |
"Choose, compare & if necessary exchange random indices n times, using the | |
implicit ordering given by the lookup function" | |
[lookup s n] | |
(let [a (to-array s) | |
c (alength a)] | |
(dotimes [_ n] | |
(let [idx1 (rand-int c) | |
idx2 (rand-int idx1) | |
v1 (aget a idx1) | |
v2 (aget a idx2)] | |
(when (< (lookup v1) (lookup v2)) | |
(aset a idx1 v2) | |
(aset a idx2 v1)))) | |
(vec a))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment