Skip to content

Instantly share code, notes, and snippets.

@bhenry
Created April 29, 2010 18:45
Show Gist options
  • Save bhenry/384030 to your computer and use it in GitHub Desktop.
Save bhenry/384030 to your computer and use it in GitHub Desktop.
;;problem 3 largest prime factor of 600851475143
(defn prime? [x]
(if (>= x 2) (zero? (count (filter #(divides? x %) (range 2 (inc (int (sqrt x))))))) false))
(defn get-biggest-prime-factor [x]
(if (prime? x)
x
(/ x (first
(filter #(prime? (/ x %))
(filter #(divides? x %)
(range 2 (inc (int (sqrt x))))))))))
(get-biggest-prime-factor 600851475143)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment