Last active
October 14, 2018 18:15
-
-
Save sevperez/e7089764d3269b029e8684838c80e966 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
(ns number-analyzer.core) | |
(declare print-factorials) | |
(defn -main [& args] | |
(print-factorials [0 1 2 3 4 5 10])) | |
; Prints: | |
; 0! = 1 | |
; 1! = 1 | |
; 2! = 2 | |
; 3! = 6 | |
; 4! = 24 | |
; 5! = 120 | |
; 10! = 3628800 | |
(defn- factorial [n] | |
(loop [n n | |
acc 1] | |
(if (< n 2) | |
acc | |
(recur (dec n) (* acc n))))) | |
(defn print-factorials [numbers] | |
(doseq [num numbers] | |
(println (str num "! = " (factorial num))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment