(ns clojure.examples.almostprime
	(:gen-class))

(defn divisors [n]
    " Finds divisors by looping through integers 2, 3,...i.. up to sqrt (n) [note: rather than compute sqrt(), test with i*i <=n] "
    (let [div (some #(if (= 0 (mod n %)) % nil) (take-while #(<= (* % %) n) (iterate inc 2)))]
        (if div                                                         
            (into [] (concat (divisors div) (divisors (/ n div))))      
            [n])))                                                      

(defn divisors-k [k n]
    " Finds n numbers with k divisors.  Does this by looping through integers 2, 3, ... filtering (passing) ones with k divisors and 
      taking the first n "
    (->> (iterate inc 2)            
         (map divisors)             
         (filter #(= (count %) k))  
         (take n)                   
         (map #(apply * %))))       

(println (for [k (range 1 6)]
          (println "k:" k (divisors-k k 10))))

}