Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(defn C [n]
(one? n) 1
(even? n) (C (div n 2))
:else (C (add1 (times 3 n)))))
(defn C* [n]
(= 1 n) 1
(clojure.core/even? n) (C (quot n 2))
:else (C (inc (* n 3)))))
(defn try-with-C [f upto]
(map (fn [n]
(try (f n)
(catch Exception e "Exception")))
(range 1 (inc upto))))
;; Wow!
(time (try-with-C C 100)) ;; "Elapsed time: 0.072 msecs"
(time (try-with-C C* 100)) ;; "Elapsed time: 0.069 msecs"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.