-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
;; https://4clojure.oxal.org/#/problem/074 | ||
|
||
(ns ex.q074) | ||
|
||
(defn ans | ||
"Problem 74, Filter Perfect Squares" | ||
[s] | ||
(letfn [(square? [x] | ||
(cond | ||
(< x 1) false | ||
(let [y (int (Math/sqrt x))] (= (* y y) x)) true))] | ||
(->> s | ||
(re-seq #"\d+") | ||
(map #(Integer/parseInt %)) | ||
(filter square?) | ||
(interpose ",") | ||
(apply str)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
;; https://4clojure.oxal.org/#/problem/075 | ||
|
||
(ns ex.q075) | ||
|
||
(defn ans | ||
"Problem 75, Euler's Totient Function" | ||
[x] | ||
(letfn [(gcd [x y] | ||
(loop [x x y y] | ||
(if (= x y) x (recur (- (max x y) (min x y)) (min x y))))) | ||
(coprime? [x y] (= 1 (gcd x y))) | ||
(coprimes [y] (filter #(coprime? y %) (range 1 y)))] | ||
(if (< x 2) 1 (count (coprimes x))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
;; https://4clojure.oxal.org/#/problem/074 | ||
|
||
(ns ex.q074-test | ||
(:require [clojure.test :as t] | ||
[ex.q074 :as sut])) | ||
|
||
(t/deftest test-q74 | ||
(t/testing "Problem 74, Filter Perfect Squares" | ||
(t/is (= "4,9" (sut/ans "4,5,6,7,8,9"))) | ||
(t/is (= "16,25,36" (sut/ans "15,16,25,36,37"))) | ||
(t/is (= "1,9,100" (sut/ans "1,2,5,6,9,11,20,30,100,101"))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
;; https://4clojure.oxal.org/#/problem/075 | ||
|
||
(ns ex.q075-test | ||
(:require [clojure.test :as t] | ||
[ex.q075 :as sut])) | ||
|
||
(t/deftest test-q75 | ||
(t/testing "Problem 75, Euler's Totient Function" | ||
(t/is (= 1 (sut/ans 1))) | ||
(t/is (= (count '(1 3 7 9)) 4 (sut/ans 10))) | ||
(t/is (= 16 (sut/ans 40))) | ||
(t/is (= 60 (sut/ans 99))))) |