2 ;(alias 'cl 'clojure.core)
4 (defn neg-index [cnt x]
5 (if (neg? x) (+ cnt x) x))
8 (let [[i j] (map (partial neg-index (count s)) [i j])]
9 (assoc (assoc (vec s) i (nth s j))
13 (defn search-non-zero [mat pivot]
14 (let [width (count (first mat))
16 (first (for [j (range pivot (dec width))
17 i (range pivot height)
18 :when (not= 0 (nth (nth mat i) j))]
22 (let [width (count (first mat))
24 (loop [pivot 0 m (vec (map vec mat))]
25 (if (>= pivot (max (dec width) height))
27 (let [[col row] (search-non-zero mat pivot)]
32 (map (partial swap pivot col) m)