Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: smerrill/project-euler-clojure
base: 9b151e5989
...
head fork: smerrill/project-euler-clojure
compare: 5ca3925d07
  • 2 commits
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Commits on Jul 29, 2012
Steven Merrill Add a (theoretically working) version of problem 3. c1c9418
Steven Merrill 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
View
@@ -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.