Last active
May 24, 2018 03:12
-
-
Save athos/1e4a8d9d0f96d9ecaf9041ae1f9e4fa7 to your computer and use it in GitHub Desktop.
Revisions
-
athos revised this gist
May 24, 2018 . 1 changed file with 20 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -8,4 +8,24 @@ ;; => (time (/ 1 (first (a&b 100)))) ;; "Elapsed time: 0.04547 msecs" ;; 3.141592653589795 ;; => (declare b) (defn ^:dynamic a [n] (if (= n 0) (/ 1 (* 2 (Math/pow 3 0.5))) (/ (+ (a (- n 1)) (b (- n 1))) 2))) (defn ^:dynamic b [n] (if (= n 0) (/ 1.0 3) (Math/pow (* (a n) (b (- n 1))) 0.5))) ;; => (time ;; (binding [a (memoize a) ;; b (memoize b)] ;; (/ 1 (a 100)))) ;; "Elapsed time: 1.764405 msecs" ;; 3.141592653589795 ;; => -
athos created this gist
May 24, 2018 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ (defn a&b [n] (loop [n n, a (/ 1.0 (* 2 (Math/pow 3 0.5))), b (/ 1.0 3)] (if (= n 0) [a b] (let [a' (/ (+ a b) 2)] (recur (dec n) a' (Math/pow (* a' b) 0.5)))))) ;; => (time (/ 1 (first (a&b 100)))) ;; "Elapsed time: 0.04547 msecs" ;; 3.141592653589795 ;; =>