Commits

Victor Iacoban  committed 0c100d2

27

  • Participants
  • Parent commits 09b69da

Comments (0)

Files changed (9)

File src/main/clojure/euler/prob001.clj

-(ns euler.prob001
-  (:use clojure.test))
+(ns euler.prob001)
 
-(with-test
-  (defn euler1 []
-    (->> (range 1 1000)
-      (filter #(or (zero? (mod % 3)) (zero? (mod % 5))))
-      (reduce +)))
-
-  (is (= 233168 (euler1))))
+(defn euler1 []
+  (->> (range 1 1000)
+    (filter #(or (zero? (mod % 3)) (zero? (mod % 5))))
+    (reduce +)))

File src/main/clojure/euler/prob002.clj

 (ns euler.prob002
-  (:use clojure.test)
   (:use tools.fibonacci))
 
-(with-test
-  (defn euler2 []
-    (->> (fibonacci-seq)
-      (take-while #(< % 4000000))
-      (filter #(zero? (mod % 2)))
-      (reduce +)))
-
-  (is (= 4613732M (euler2))))
+(defn euler2 []
+  (->> (fibonacci-seq)
+    (take-while #(< % 4000000))
+    (filter #(zero? (mod % 2)))
+    (reduce +)))

File src/main/clojure/euler/prob003.clj

 (ns euler.prob003
-  (:use clojure.test)
   (:use tools.primes))
 
-(with-test
-  (defn euler3 []
-    (reduce max (prime-decomposition 600851475143)))
-
-  (is (= 6857 (euler3))))
+(defn euler3 []
+  (reduce max (prime-decomposition 600851475143)))

File src/main/clojure/euler/prob004.clj

-(ns euler.prob004
-  (:use clojure.test))
+(ns euler.prob004))
 
 (defn to-palindrome [n]
   (read-string (str (str n) (clojure.string/reverse (str n)))))
 (defn is-acceptable? [p]
   (seq (for [x (range 100 1000) :when (and (zero? (mod p x)) (< (/ p x) 1000))] [x (/ p x)])))
 
-(with-test
-  (defn euler4 []
-    (first (filter is-acceptable? (reverse (map to-palindrome (range 100 1000))))))
-
-  (is (= 906609 (euler4))))
+(defn euler4 []
+  (first (filter is-acceptable? (reverse (map to-palindrome (range 100 1000))))))

File src/main/clojure/euler/prob005.clj

 (ns euler.prob005
-  (:use clojure.test)
   (:use tools.primes))
 
 (defn count-element [x e]
   (let [e (distinct (concat x y))]
     (flatten (map #(repeat (max (count-element x %) (count-element y %)) %) e))))
 
-(with-test
-  (defn euler5 [n]
-    (reduce * (reduce get-factors (map prime-decomposition (range 1 n)))))
-
-  (is (= 232792560 (euler5 20))))
+(defn euler5 [n]
+  (reduce * (reduce get-factors (map prime-decomposition (range 1 n)))))

File src/main/clojure/euler/prob006.clj

-(ns euler.prob006
-  (:use clojure.test))
+(ns euler.prob006)
 
 (defn square [n] (* n n))
 
-(with-test
-  (defn euler6 [n]
-      (- (square (* (inc n) (/ n 2))) (reduce + (map square (range 1 (inc n))))))
-
-  (is (= 25164150 (euler6 100))))
+(defn euler6 [n]
+  (- (square (* (inc n) (/ n 2))) (reduce + (map square (range 1 (inc n))))))

File src/main/clojure/euler/prob007.clj

 (ns euler.prob007
-  (:use clojure.test)
   (:use tools.primes))
 
 (defn euler7 [n]

File src/main/clojure/euler/prob027.clj

 (ns euler.prob027
-  (:use tool.primes))
+  (:use tools.primes))
 
-(defn euler27 []
+(defn eq [a b n]
+  (+ (* n n) (* a n) b))
 
-  )
+(defn take2[m n]
+  (for [a (range m (inc n)) b (range m (inc n))]
+    [(count (take-while #(is-prime? (eq a b %)) (range))) [a b]]))
+
+(defn euler27 [m n]
+  (take-last 1 (sort-by first (take2 m n))))

File src/main/clojure/repl.clj

+