Skip to content

Instantly share code, notes, and snippets.

@luxbock
Created April 16, 2015 07:48
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 luxbock/6ee01a0fd51367e14380 to your computer and use it in GitHub Desktop.
Save luxbock/6ee01a0fd51367e14380 to your computer and use it in GitHub Desktop.
C
(defn C [n]
(cond
(one? n) 1
(even? n) (C (div n 2))
:else (C (add1 (times 3 n)))))
(defn C* [n]
(cond
(= 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))))
(comment
;; 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