Sha256: cf89953982df69d71a9bc4ecbf9f480b72f352621c0a3d5fa0fe26f287428e8c

Contents?: true

Size: 348 Bytes

Versions: 145

Compression:

Stored size: 348 Bytes

Contents

(ns collatz-conjecture)

(defn collatz-helper [n]
  (cond (= 1 n)   1
        (even? n) (/ n 2)
        :else     (inc (* 3 n))))

(defn collatz [n]
  (if (> n 0)
    (count (take-while #(not= 1 %)
                       (iterate collatz-helper n)))
    (throw (IllegalArgumentException.
             "Just defined for numbers greater than 0."))))

Version data entries

145 entries across 145 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/clojure/exercises/collatz-conjecture/src/example.clj
trackler-2.2.1.179 tracks/clojure/exercises/collatz-conjecture/src/example.clj
trackler-2.2.1.178 tracks/clojure/exercises/collatz-conjecture/src/example.clj
trackler-2.2.1.177 tracks/clojure/exercises/collatz-conjecture/src/example.clj
trackler-2.2.1.176 tracks/clojure/exercises/collatz-conjecture/src/example.clj
trackler-2.2.1.175 tracks/clojure/exercises/collatz-conjecture/src/example.clj
trackler-2.2.1.174 tracks/clojure/exercises/collatz-conjecture/src/example.clj
trackler-2.2.1.173 tracks/clojure/exercises/collatz-conjecture/src/example.clj
trackler-2.2.1.172 tracks/clojure/exercises/collatz-conjecture/src/example.clj
trackler-2.2.1.171 tracks/clojure/exercises/collatz-conjecture/src/example.clj
trackler-2.2.1.170 tracks/clojure/exercises/collatz-conjecture/src/example.clj
trackler-2.2.1.169 tracks/clojure/exercises/collatz-conjecture/src/example.clj
trackler-2.2.1.167 tracks/clojure/exercises/collatz-conjecture/src/example.clj
trackler-2.2.1.166 tracks/clojure/exercises/collatz-conjecture/src/example.clj
trackler-2.2.1.165 tracks/clojure/exercises/collatz-conjecture/src/example.clj
trackler-2.2.1.164 tracks/clojure/exercises/collatz-conjecture/src/example.clj
trackler-2.2.1.163 tracks/clojure/exercises/collatz-conjecture/src/example.clj
trackler-2.2.1.162 tracks/clojure/exercises/collatz-conjecture/src/example.clj
trackler-2.2.1.161 tracks/clojure/exercises/collatz-conjecture/src/example.clj
trackler-2.2.1.160 tracks/clojure/exercises/collatz-conjecture/src/example.clj