Skip to content

Instantly share code, notes, and snippets.

@bonifaido
Created December 6, 2011 09:52
Show Gist options
  • Save bonifaido/1437597 to your computer and use it in GitHub Desktop.
Save bonifaido/1437597 to your computer and use it in GitHub Desktop.
Detects if given integer is a prime?
; Clojure step 1
(defn is-prime? [n]
"Detects if input paramter is a prime."
(if (<= n 3)
true
(let [max (Math/floor (Math/sqrt n))]
(loop [d 2]
(if (zero? (rem n d))
false
(if (> d max)
true
(recur (inc d))))))))
(defn ARGV [n] (Long. (nth *command-line-args* n)))
(println (is-prime? (ARGV 0)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment