Here's the code...
My goal is to simulate a Pile shuffle of a vector.
Here's the function..
(defn pile
([cards] (pile cards 3 1))
([cards num_piles] (pile cards num_piles 1))
([cards num_piles times]
(loop [i 1
piles (transient (vec (map (fn [p] []) (range num_piles))))
the_pile 0]
(if (<= i (count cards))
(recur (inc i)
(assoc!
piles
the_pile
(vec (concat [(nth cards (dec i))]
(nth piles the_pile))))
(rem i num_piles))
(if (> times 1)
(pile (reduce into (persistent! piles)) num_piles (dec times) )
(vec (reduce into (persistent! piles))))))))
It takes 2 optional arguments for the number of piles to use and how many times to perform the shuffle.
As this is my first attempt at clojure code, I'm fairly sure I'm doing something terribly wrong here... I'm also concerned with speed and efficiency.
Also I'd appreciate any pointers that would make this function more generic (maybe not restricting to vectors, but general collections)
Also, indentation style.