Scamble a vector, preserving the sum My first crack at clojure... if you have time to provide input, I'd appreciate it. I'm as much interested in style as proper usage. I'm just getting started.

The task to start with an vector of N zeros, and then "scramble" it by: Select 2 items in the vector. If one is less than 4, and the other is greater than -4, increment one and decrement the other -- so that the sum of the vector remains the same.


am I abusing let?
this generates a sequence of vectors, and I take the last one. Is there a better way to iterate and get the last result?
what tricks that I've missed?
this is just a small sample ;) but what community standards and practices have I missed?


code

(defn level [c] (let [n+ (rand-int (count c))
               n- (rand-int (count c))
               v+ (inc (nth c n+))
               v- (dec (nth c n-))
               go (and (not= n+ n-) (&lt; v+ 4) (&gt; v- -4))
               ]
           (if go (assoc (assoc c n+ v+) n- v-) c)
           ))

(defn rseq [n]
      (let [first (vec (repeat n 0))]
        (last (take (* n 2) (iterate level first)))))

(rseq 16)

(deftest rseq-sum-equals-2
  (let [actual (rseq 16)]
  (is (= 0 (apply + actual)))))
(run-tests 'ursound.core)
I am also relatively new to Clojure, but here are my first thoughts:


I like that you work with a vector, because random access of vectors with (nth) and assoc is faster. I also like your naming. thanks for providing a deftest, but please, user a proper inlining.
(assoc)'s do not need to be nested: (assoc (assoc c n+ v+) n- v-) is the same as (assoc c n+ v+ n- v-).
(last (take n x)) can be written as (nth x n).
Warning: you use the name 'first in yout (let), but this name is already defined in clojure.core.
For a style guide, please see https://github.com/bbatsov/clojure-style-guide


That is all for now, and I hope you found some advice useful.