         (recur (inc stop))))))
 
 (defn finish
+  "Takes raw-chunk - transient vector of primes to process
+         my-num    - this machines number
+  and writes the contents to a file"
   [raw-chunk my-num]
   (println "Writing primes to file...")
   (when (= 1 my-num)

                  (println "Appointed as new lead.\n")
                  (sieve-e my-num true (chan 100) chunk out-channel))
                (recur)))))))))

(defn dis-sieve-e
  [num-machines n]
  (let [debug (vec (repeat num-machines (chan 100000000)))]
    (loop [i 1
           chunks (mapv gen-table (spread-work n num-machines))
           mach-chans (repeat num-machines (chan (* num-machines n 2)))]
      (when-not (= i (inc num-machines))
        (if (= i 1)
          (do
            (println "starting lead machine...")
                                        ;Make a lead machine
            (sieve-e 1 true (chan 10) (first chunks) mach-chans (first debug))
            (recur (inc i) (rest chunks) mach-chans))
          (do
            (println "starting following machine" i "...")
            (sieve-e i false (first mach-chans) (first chunks) (rest mach-chans) (get debug (dec i)))
            (recur (inc i) (rest chunks) (rest mach-chans))))))
    debug))

            [clojure.string :refer [join]])
  (:import [java.io FileWriter]))

;; Main logic for the sieve

(defn gen-table
  "Given: [lower upper] - lower bound int and upper bound int
  produces a transient vector between those ranges skip counting by 2"
  [[lower upper]]
  (transient (vec (range lower upper 2))))

