Skip to content

Instantly share code, notes, and snippets.

@ponkore
Created April 26, 2012 02:16
Show Gist options
  • Save ponkore/2495233 to your computer and use it in GitHub Desktop.
Save ponkore/2495233 to your computer and use it in GitHub Desktop.
Project Euler Problem 7
;;; By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
;;; What is the 10 001st prime number?
(defn primes [n] (primes- '(2) (take (dec n) (iterate inc 2))))
(defn primes- [prime-list search-list]
(let [prime-list-max (first prime-list)
search-list-max (apply max search-list)
search-list-next (filter #(not (zero? (mod % prime-list-max))) search-list)]
(if (< search-list-max (* prime-list-max prime-list-max))
(sort (concat prime-list search-list-next))
(primes- (conj prime-list (first search-list-next)) search-list-next))))
(def primes-1000000 (primes 1000000))
(count primes-1000000)
;;;=>78498
(take 1 (drop 10000 primes-1000000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment