If this is significantly faster than c.c.seq/shuffle, you should
submit a patch. I know Rich was complaining about the speed of that
fn in the past.
Also, I'd reverse the arg order of with-transient. I think
(with-transient f x)
reads easier. Also, it should probably end with a bang, because
In my experiments my code is still about 1.5x slower than
seq-utils.shuffle. The current implementation of seq-utils.shuffle
simply converts to an ArrayList, calls java.util.Collections.shuffle,
and converts back to a Clojure sequence. Here's a quick experiment:
user (def v (vec (range 50)))
I'm overwhelmed by the answers, thank you all! Now back to the REPL.
/Linus
2010/4/5 Per Vognsen per.vogn...@gmail.com
On Mon, Apr 5, 2010 at 11:33 AM, Lee Spector lspec...@hampshire.edu
wrote:
Ah -- maybe that foiled my timings too. I didn't expect it to be fast --
just clear (at least
Hello Clojure!
Is there any straight-forward way to randomly reorder a list?
ie:
(randomize-list (list 1 2 3 4))
- (3 2 1 4)
Regards,
Linus Ericsson
--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure
There's a shuffle function in seq-utils:
user= (use 'clojure.contrib.seq-utils)
nil
user= (shuffle (list 1 2 3 4))
(3 4 1 2)
-Lee
On Apr 4, 2010, at 4:14 PM, Linus Ericsson wrote:
Hello Clojure!
Is there any straight-forward way to randomly reorder a list?
ie:
(randomize-list
)
(defn knuth-shuffle [xs]
(let [v (vec xs)]
(reduce #(swap-elts %1 %2 (rand-range %2 (count %1))) v (range (count v)
-Per
On Mon, Apr 5, 2010 at 3:14 AM, Linus Ericsson
oscarlinuserics...@gmail.com wrote:
Hello Clojure!
Is there any straight-forward way to randomly reorder
!
Is there any straight-forward way to randomly reorder a list?
ie:
(randomize-list (list 1 2 3 4))
- (3 2 1 4)
Regards,
Linus Ericsson
--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure
(vec xs)]
(reduce #(swap-elts %1 %2 (rand-range %2 (count %1))) v (range (count
v)
-Per
On Mon, Apr 5, 2010 at 3:14 AM, Linus Ericsson
oscarlinuserics...@gmail.com wrote:
Hello Clojure!
Is there any straight-forward way to randomly reorder a list?
ie:
(randomize-list (list 1 2
On my system, knuth-shuffle performs several times faster than Spector's
recursive functional shuffle on smallish lists, and the difference grows
even more dramatic as the list grows, which is what I'd expect (since
knuth-shuffle is O(n) and shuffle is O(n^2)).
--
You received this message
Wow, you're right. The partial laziness of his code was foiling my benchmark.
-Per
On Mon, Apr 5, 2010 at 11:05 AM, Mark Engelberg
mark.engelb...@gmail.com wrote:
On my system, knuth-shuffle performs several times faster than Spector's
recursive functional shuffle on smallish lists, and the
Ah -- maybe that foiled my timings too. I didn't expect it to be fast -- just
clear (at least to this Lisp programmer).
-Lee
On Apr 5, 2010, at 12:11 AM, Per Vognsen wrote:
Wow, you're right. The partial laziness of his code was foiling my benchmark.
-Per
On Mon, Apr 5, 2010 at 11:05
On Mon, Apr 5, 2010 at 11:33 AM, Lee Spector lspec...@hampshire.edu wrote:
Ah -- maybe that foiled my timings too. I didn't expect it to be fast -- just
clear (at least to this Lisp programmer).
Embrace recursion combinators! They are warm and fuzzy!
Here's a gist of the final cleaned up
12 matches
Mail list logo