Skip to content

Instantly share code, notes, and snippets.

@bmorphism
Created March 27, 2015 01:41
Show Gist options
  • Save bmorphism/53d883789e041571d9f3 to your computer and use it in GitHub Desktop.
Save bmorphism/53d883789e041571d9f3 to your computer and use it in GitHub Desktop.
Euler's totient function
(defn totient [num]
(if (= 1 num) 1
(let [gcd (fn [a b]
(if (= b 0)
a
(recur b (rem a b))))]
(count (filter #(= 1 (gcd % num)) (range 1 num))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment