Skip to content

Instantly share code, notes, and snippets.

@kevgathuku
Last active January 2, 2019 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevgathuku/5cc24d170e8ba1c37adf800439dbc812 to your computer and use it in GitHub Desktop.
Save kevgathuku/5cc24d170e8ba1c37adf800439dbc812 to your computer and use it in GitHub Desktop.
(defn compute-collatz [num steps]
(cond
(= num 1) steps
(even? num) (compute-collatz (/ num 2) (inc steps))
(odd? num) (compute-collatz (+ 1 (* num 3)) (inc steps))))
(defn collatz [num]
{:pre [(pos? num)]}
(compute-collatz num 0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment