(ns example
  (:gen-class))

(defn factors [n]
  " Find the proper factors of a number "
  (into (sorted-set)
        (mapcat (fn [x] (if (= x 1) [x] [x (/ n x)]))
                (filter #(zero? (rem n %)) (range 1 (inc (Math/sqrt n)))) )))


(def find-pairs (into #{}
               (for [n (range  2 20000)
                  :let [f (factors n)     
                        M (apply + f)     
                        g (factors M)     
                        N (apply + g)]    
                  :when (= n N)           
                  :when (not= M N)]       
                 (sorted-set n M))))      


(doseq [q find-pairs]
  (println q))