   [c v]
     (for [i c :let [d (distance i v)]] d))
 
+(defn make-vector
+  "create a vector containing n cols"
+  ([n] (make-vector n []))
+  ([n c]
+    (cond
+      (<= n 0) c
+      :else
+        (recur (dec n) (conj c [])))))
+
 (defn cluster
   "take a vector and cluster it via distance"
   [g l c]
-  (println g)
   (cond
-    (empty? g) (recur (hash-set (range 0 (count c))) l c)
-    (not-empty l) (recur (conj (first l) (get g (min-index (min-distance c (first l))))) (rest l) c)
+    (nil? g) (recur (make-vector (count c)) l c)
+    (not-empty l)
+      (let [i (min-index (min-distance c (first l)))]
+        (recur (assoc g i (conj (nth g i) (first l))) (rest l) c))
     :else
     g))
 


(defn distance
  "Implements euclidian distance between two vectors"
  ([[p1 p2] [q1 q2]]
    (Math/sqrt (+ (Math/pow (- q1 q2) 2) (Math/pow (- p1 p2) 2)))))
    ; (->> (map - c1 c2) (map #(* % %)) (reduce +))))) ; This is a better implementation for when this gets parallelised

(defn min-index
  [c]

(defn k-means
  "Perform the actual k-means"
  ([l k]
    (k-means l k (choose-initial-centroids l k) (make-vector k)))
  ([l k c g]
    (let [t c g (cluster g l c) c (mean-centroids g)]
      ; (println g)
      (cond
        (still-moving? t c) ; Keep shifting centroids until equilibrium
          ; (recur nil k c g)
          g
        :else g))))
