Skip to content

Instantly share code, notes, and snippets.

@sevperez
Last active October 14, 2018 18:15
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 sevperez/e7089764d3269b029e8684838c80e966 to your computer and use it in GitHub Desktop.
Save sevperez/e7089764d3269b029e8684838c80e966 to your computer and use it in GitHub Desktop.
(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