diff options
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})))) |
