aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTyler Wardhaugh <tyler.wardhaugh@gmail.com>2020-10-13 09:10:27 -0700
committerTyler Wardhaugh <tyler.wardhaugh@gmail.com>2020-10-13 10:24:31 -0700
commit880c625c67d348ddb591740ece65c38cb2a70648 (patch)
tree9e3731ac84843f12558b90eb29a6cca48671ada6
parent5eeb31e3578b50b15e7831d062e6a1a169c354d7 (diff)
downloadperlweeklychallenge-club-880c625c67d348ddb591740ece65c38cb2a70648.tar.gz
perlweeklychallenge-club-880c625c67d348ddb591740ece65c38cb2a70648.tar.bz2
perlweeklychallenge-club-880c625c67d348ddb591740ece65c38cb2a70648.zip
Ch82: Task 1
-rw-r--r--challenge-082/tyler-wardhaugh/clojure/src/tw/weekly/c82/core.clj9
-rw-r--r--challenge-082/tyler-wardhaugh/clojure/src/tw/weekly/c82/t1.clj24
-rw-r--r--challenge-082/tyler-wardhaugh/clojure/test/tw/weekly/c82_test.clj8
3 files changed, 41 insertions, 0 deletions
diff --git a/challenge-082/tyler-wardhaugh/clojure/src/tw/weekly/c82/core.clj b/challenge-082/tyler-wardhaugh/clojure/src/tw/weekly/c82/core.clj
new file mode 100644
index 0000000000..723a65d626
--- /dev/null
+++ b/challenge-082/tyler-wardhaugh/clojure/src/tw/weekly/c82/core.clj
@@ -0,0 +1,9 @@
+(ns tw.weekly.c82.core
+ (:require [tw.weekly.c82.t1 :as t1])
+ (:gen-class))
+
+(defn -main
+ "Run all tasks"
+ [& _]
+ (println "Task #1")
+ (t1/-main))
diff --git a/challenge-082/tyler-wardhaugh/clojure/src/tw/weekly/c82/t1.clj b/challenge-082/tyler-wardhaugh/clojure/src/tw/weekly/c82/t1.clj
new file mode 100644
index 0000000000..1b2713d772
--- /dev/null
+++ b/challenge-082/tyler-wardhaugh/clojure/src/tw/weekly/c82/t1.clj
@@ -0,0 +1,24 @@
+(ns tw.weekly.c82.t1
+ (:require [clojure.edn :as edn]))
+
+;;; Task description for TASK #1 › Common Factors
+; Submitted by: Niels van Dijke
+; You are given 2 positive numbers $M and $N.
+;
+; Write a script to list all common factors of the given numbers.
+;;;
+
+(defn common-factors
+ "Determine the common factors for m and n."
+ [m n]
+ (let [[m n] (sort [m n])
+ source (concat (range 1 (inc (quot n 2))) [n])
+ xf (filter (fn [x] (= 0 (rem n x) (rem m x))))]
+ (into (sorted-set) xf source)))
+
+(defn -main
+ "Run Task 1 with two strings A and B, defaulting to the first example given in the task description."
+ [& args]
+ (let [[M N] (or (some->> args (take 2) (map edn/read-string)) [12 18])
+ factors (common-factors M N)]
+ (println (seq factors))))
diff --git a/challenge-082/tyler-wardhaugh/clojure/test/tw/weekly/c82_test.clj b/challenge-082/tyler-wardhaugh/clojure/test/tw/weekly/c82_test.clj
new file mode 100644
index 0000000000..20c4ddfd5b
--- /dev/null
+++ b/challenge-082/tyler-wardhaugh/clojure/test/tw/weekly/c82_test.clj
@@ -0,0 +1,8 @@
+(ns tw.weekly.c82-test
+ (:require [clojure.test :refer [deftest is testing]]
+ [tw.weekly.c82.t1 :refer [common-factors]]))
+
+(deftest task-1
+ (testing "Task 1, Common Factors"
+ (is (= (common-factors 12 18) #{1 2 3 6}))
+ (is (= (common-factors 18 23) #{1}))))