Created
June 17, 2010 15:30
-
-
Save raek/442269 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 fac [n] | |
(loop [n n, acc 1] | |
(if (zero? n) | |
acc | |
(recur (dec n) (* acc n))))) | |
(fac 20) | |
; => 2432902008176640000 | |
(fac 25) | |
; => java.lang.ArithmeticException: integer overflow | |
(fac 20N) | |
; => 2432902008176640000 | |
(fac 25N) | |
; => 7034535277573963776 | |
(fac 26N) | |
; => -1569523520172457984 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(defn fac [n](loop [n n, acc %28num 1%29]
%28if %28zero? n%29
acc
%28recur %28dec n%29 %28* acc n%29%29%29))