(ns rosettacode.hofstader-conway
  (:use [clojure.math.numeric-tower:only [expt]]))


(def conway
  (memoize
    (fn [x]
      (if (< x 3)
        1
        (+  (-> x dec conway conway)
           (->> x dec conway (- x) conway))))))

(let [N      (drop 1 (range))
      pow2   (map #(expt 2 %) N)
      
      groups (partition-by (fn [x] (filter #(> % x) pow2)) N)
      maxima (->> (map #(map conway %) groups)
                  (map #(map / %2 %1) groups)  
                  (map #(apply max %)))
      m20    (take 20 maxima)]
  (println
    (take 4 maxima) "\n"
    (apply >= m20)  "\n"
    (map double m20)))