Commits

Victor Iacoban  committed 09b69da

cleanup

  • Participants
  • Parent commits 8d9e0a4

Comments (0)

Files changed (12)

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

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

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

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

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

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

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

-(ns euler.prob004)
+(ns euler.prob004
+  (:use clojure.test))
 
 (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)])))
 
-(defn euler4 []
-  (first (filter is-acceptable? (reverse (map to-palindrome (range 100 1000))))))
+(with-test
+  (defn euler4 []
+    (first (filter is-acceptable? (reverse (map to-palindrome (range 100 1000))))))
+
+  (is (= 906609 (euler4))))

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))))
 
-(defn euler5 [n]
-  (reduce * (reduce get-factors (map prime-decomposition (range 1 n)))))
+(with-test
+  (defn euler5 [n]
+    (reduce * (reduce get-factors (map prime-decomposition (range 1 n)))))
+
+  (is (= 232792560 (euler5 20))))

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

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

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

 (ns euler.prob007
+  (:use clojure.test)
   (:use tools.primes))
 
 (defn euler7 [n]
-  (take-last 1 (take n (primes-lazy-seq))))
+  (take-last 1 (take n (primes-seq))))

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

   (:use tools.primes))
 
 (defn euler10 []
-  (reduce + (for [x (primes-lazy-seq) :while (< x 2000000)] x)))
+  (reduce + (for [x (primes-seq) :while (< x 2000000)] x)))

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

 (defn euler25 [n]
   (let [limit (.pow 10M (dec n))]
     (inc (count (take-while #(< % limit) (fibonacci-seq))))))
-
-

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

+(ns euler.prob027
+  (:use tool.primes))
+
+(defn euler27 []
+
+  )

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

-(ns euler.repl)

File src/main/clojure/tools/primes.clj

         (> f r) true
         :else (recur (+ 6 f)))))))
 
-(defn primes-lazy-seq []
-  (for [i (range) :when (is-prime? i)] i))
+(defn primes-seq []
+  (filter is-prime? (range)))
 
 (defn count-divisors [n]
   (let [f (frequencies (prime-decomposition n))]