Re: shuffle vector in Clojure

2008-08-27 Thread Shawn Hoover
On Wed, Aug 27, 2008 at 6:59 AM, Rich Hickey <[EMAIL PROTECTED]> wrote: > While I appreciate the intellectual exercise (and would point you to > http://okmij.org/ftp/Haskell/perfect-shuffle.txt if you haven't seen > it), one of the nice things about Clojure is that you aren't trapped > without mut

Re: shuffle vector in Clojure

2008-08-27 Thread Shawn Hoover
On Wed, Aug 27, 2008 at 12:11 AM, Chouser <[EMAIL PROTECTED]> wrote: > > > You could simplify your reduce fn a bit by using merge-with: > Or even: > > (defn test-shuffle-uniformity > "Shuffles a 3-item collection n times, mapping each result to the number > of > times it's hit. If the distributi

Re: shuffle vector in Clojure

2008-08-27 Thread Rich Hickey
On Aug 26, 11:54 pm, "Shawn Hoover" <[EMAIL PROTECTED]> wrote: > I needed to shuffle a vector so I decided to try doing it functionally. > Below is the implementation and a couple exercise functions, inspired > byhttp://en.wikipedia.org/wiki/Fisher-Yates_shuffleandhttp://szeryf.wordpress.com/20

Re: shuffle vector in Clojure

2008-08-27 Thread Chouser
> You could simplify your reduce fn a bit by using merge-with: Or even: (defn test-shuffle-uniformity "Shuffles a 3-item collection n times, mapping each result to the number of times it's hit. If the distribution isn't uniform we've let bias into the random numbers or the algorithm. Typica

Re: shuffle vector in Clojure

2008-08-26 Thread Chouser
On Tue, Aug 26, 2008 at 11:54 PM, Shawn Hoover <[EMAIL PROTECTED]> wrote: > For one thing, it seems like there must be a cleaner way to handle > my use of reduce in test-shuffle-uniformity. I like reduce for > looping functionally, but in this case I just need to run n times > regardless of the sp