File tree Expand file tree Collapse file tree 3 files changed +27
-1
lines changed Expand file tree Collapse file tree 3 files changed +27
-1
lines changed Original file line number Diff line number Diff line change 8
8
(some #(when (= 0 (rem x %) (rem y %)) %) (range (min x y) 0 -1 )))
9
9
10
10
(defn ans2
11
- " Problem 66, using Euclid's algorithm (https://en.wikipedia.org/wiki/Greatest_common_divisor#Euclid's_algorithm)"
11
+ " Problem 66, using Euclid's algorithm,
12
+ https://en.wikipedia.org/wiki/Greatest_common_divisor#Euclid's_algorithm"
12
13
[x y]
13
14
(loop [x x y y]
14
15
(if (= x y) x (recur (- (max x y) (min x y)) (min x y)))))
Original file line number Diff line number Diff line change
1
+ ; ; https://4clojure.oxal.org/#/problem/067
2
+
3
+ (ns ex.q067 )
4
+
5
+ (defn ans
6
+ " Problem 67, Prime Numbers"
7
+ [y]
8
+ (letfn [(prime? [x]
9
+ (cond
10
+ (< x 2 ) false
11
+ (= x 2 ) true
12
+ (even? x) false
13
+ :else (not-any? zero? (map #(mod x %) (range 3 (inc (Math/sqrt x)) 2 )))))]
14
+ (take y (filter prime? (range )))))
Original file line number Diff line number Diff line change
1
+ ; ; https://4clojure.oxal.org/#/problem/067
2
+
3
+ (ns ex.q067-test
4
+ (:require [clojure.test :as t]
5
+ [ex.q067 :as sut]))
6
+
7
+ (t/deftest test-q67
8
+ (t/testing " Problem 67, Prime Numbers"
9
+ (t/is (= [2 3 ] (sut/ans 2 )))
10
+ (t/is (= [2 3 5 7 11 ] (sut/ans 5 )))
11
+ (t/is (= 541 (last (sut/ans 100 ))))))
You can’t perform that action at this time.
0 commit comments