Last active
December 1, 2019 19:26
-
-
Save kevgathuku/c9398fef53074f6cb70f7ea4b1a1bad8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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] | |
; Check if the provided number is positive. If not throw an error | |
(if | |
(pos? num) (compute-collatz num 0) | |
(throw (AssertionError. "Positive integer required.")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment