Skip to content

# smerrill/project-euler-clojure

### Subversion checkout URL

You can clone with
or
.

# Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

# Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
• 2 commits
• 1 file changed
• 0 commit comments
• 1 contributor
Commits on Jul 29, 2012
 smerrill `Add a (theoretically working) version of problem 3.` `c1c9418` smerrill `Working problem 3!` `This has lots of failed attempts commented out.` `5ca3925`
Showing with 59 additions and 0 deletions.
1. +59 −0 src/project_euler_clojure/problem3.clj
59 src/project_euler_clojure/problem3.clj
 @@ -0,0 +1,59 @@ +(ns project-euler-clojure.core) + +(comment What is the largest prime factor of the number 600851475143 .) + +;(defn divisors [n] + ;(filter #(= 0 (mod n %)) (range 1 (int (Math/sqrt n))))) + +(defn divisors [n] + (sort + (mapcat + #(list % (/ n %)) + (for [a (range 1 (+ 1(int (Math/sqrt n)))) + :when (= 0 (mod n a))] + a)))) + +;(defn lazy-divisors [n] + ;(for [a (range n 0 -1) + ;:when (= 0 (mod n a))] + ;a)) + +(defn is-prime? [n] + (and + (> n 1) + (= (divisors n) (list 1 n)))) + +;(defn lazy-prime-factors [n] + ;(for [a (lazy-divisors n) + ;:let [b (int (Math/sqrt n))] + ;:when (and (< a b) (is-prime? a))] + ;a)) + +;(defn lazy-prime-factors [n] + ;(for [a (lazy-divisors n) + ;:let [b (int (Math/sqrt n))] + ;:when (and (< a b) (is-prime? a))] + ;a)) + +;divisors(defn prime-factors [n] + ;(filter is-prime? (divisors n))) + +;(defn largest-prime-factor [n] + ;(first + ;(for [a (range n 0 -1) + ;:when (is-prime? divisors a)] + ;a))) + +(last (filter is-prime? (divisors 600851475143))) +;(divisors 600851475143) + +;(second (lazy-divisors 13195)) +;(first (lazy-prime-factors 13195)) +;(lazy-prime-factors 13195) + +;(last (prime-factors 13195)) + +;(last (prime-factors 600851475143)) + +;(is-prime? 27) +;(is-prime? 17)

### No commit comments for this range

Something went wrong with that request. Please try again.