From 5eeb31e3578b50b15e7831d062e6a1a169c354d7 Mon Sep 17 00:00:00 2001 From: Tyler Wardhaugh Date: Tue, 13 Oct 2020 09:10:27 -0700 Subject: Ch82: prep for tasks --- challenge-082/tyler-wardhaugh/clojure/README.md | 10 +++++----- challenge-082/tyler-wardhaugh/clojure/deps.edn | 7 +++---- challenge-082/tyler-wardhaugh/clojure/pom.xml | 19 +++++++------------ 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/challenge-082/tyler-wardhaugh/clojure/README.md b/challenge-082/tyler-wardhaugh/clojure/README.md index 3a0c44fe10..546cb8db65 100644 --- a/challenge-082/tyler-wardhaugh/clojure/README.md +++ b/challenge-082/tyler-wardhaugh/clojure/README.md @@ -1,13 +1,13 @@ -# tw.weekly.c81 +# tw.weekly.c82 -The Weekly Challenge - #081 - Tyler Wardhaugh +The Weekly Challenge - #082 - Tyler Wardhaugh ## Usage Run the project directly (shows default output from both tasks): - $ clojure -M -m tw.weekly.c81.core + $ clojure -M -m tw.weekly.c82.core Run the project's tests (which are samples from the task descriptions): @@ -15,11 +15,11 @@ Run the project's tests (which are samples from the task descriptions): Run Task #1 with input - $ clojure -M -m tw.weekly.c81.t1 A B + $ clojure -M -m tw.weekly.c82.t1 M N Run Task #2 with input: - $ clojure -M -m tw.weekly.c81.t2 INPUT-FILE + $ clojure -M -m tw.weekly.c82.t2 S1 S2 ## Project Template diff --git a/challenge-082/tyler-wardhaugh/clojure/deps.edn b/challenge-082/tyler-wardhaugh/clojure/deps.edn index 8bbe260e55..4010bedaeb 100644 --- a/challenge-082/tyler-wardhaugh/clojure/deps.edn +++ b/challenge-082/tyler-wardhaugh/clojure/deps.edn @@ -1,6 +1,5 @@ {:paths ["src" "resources"] - :deps {org.clojure/clojure {:mvn/version "1.10.1"} - net.cgrand/xforms {:mvn/version "0.19.2"}} + :deps {org.clojure/clojure {:mvn/version "1.10.1"}} :aliases {:test {:extra-paths ["test"] :extra-deps {org.clojure/test.check {:mvn/version "1.0.0"}}} @@ -11,5 +10,5 @@ :main-opts ["-m" "cognitect.test-runner" "-d" "test"]} :uberjar {:extra-deps {seancorfield/depstar {:mvn/version "1.0.94"}} - :main-opts ["-m" "hf.depstar.uberjar" "tw.weekly.c81.jar" - "-C" "-m" "tw.weekly.c81"]}}} + :main-opts ["-m" "hf.depstar.uberjar" "tw.weekly.c82.jar" + "-C" "-m" "tw.weekly.c82"]}}} diff --git a/challenge-082/tyler-wardhaugh/clojure/pom.xml b/challenge-082/tyler-wardhaugh/clojure/pom.xml index a997eb3a20..6fead6ac04 100644 --- a/challenge-082/tyler-wardhaugh/clojure/pom.xml +++ b/challenge-082/tyler-wardhaugh/clojure/pom.xml @@ -2,11 +2,11 @@ 4.0.0 tw.weekly - tw.weekly.c81 + tw.weekly.c82 0.1.0-SNAPSHOT - tw.weekly.c81 - Challenge #081 - https://github.com/tw.weekly/tw.weekly.c81 + tw.weekly.c82 + Challenge #082 + https://github.com/tw.weekly/tw.weekly.c82 Eclipse Public License @@ -19,9 +19,9 @@ - https://github.com/tw.weekly/tw.weekly.c81 - scm:git:git://github.com/tw.weekly/tw.weekly.c81.git - scm:git:ssh://git@github.com/tw.weekly/tw.weekly.c81.git + https://github.com/tw.weekly/tw.weekly.c82 + scm:git:git://github.com/tw.weekly/tw.weekly.c82.git + scm:git:ssh://git@github.com/tw.weekly/tw.weekly.c82.git HEAD @@ -30,11 +30,6 @@ clojure 1.10.1 - - net.cgrand - xforms - 0.19.2 - src -- cgit From 880c625c67d348ddb591740ece65c38cb2a70648 Mon Sep 17 00:00:00 2001 From: Tyler Wardhaugh Date: Tue, 13 Oct 2020 09:10:27 -0700 Subject: Ch82: Task 1 --- .../clojure/src/tw/weekly/c82/core.clj | 9 ++++++++ .../clojure/src/tw/weekly/c82/t1.clj | 24 ++++++++++++++++++++++ .../clojure/test/tw/weekly/c82_test.clj | 8 ++++++++ 3 files changed, 41 insertions(+) create mode 100644 challenge-082/tyler-wardhaugh/clojure/src/tw/weekly/c82/core.clj create mode 100644 challenge-082/tyler-wardhaugh/clojure/src/tw/weekly/c82/t1.clj create mode 100644 challenge-082/tyler-wardhaugh/clojure/test/tw/weekly/c82_test.clj 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})))) -- cgit From c0bc7cca5b312832af50c6f03dac2565b58bac4c Mon Sep 17 00:00:00 2001 From: Tyler Wardhaugh Date: Tue, 13 Oct 2020 09:10:28 -0700 Subject: Ch80: Task 2 --- .../clojure/src/tw/weekly/c82/core.clj | 9 +++++--- .../clojure/src/tw/weekly/c82/t2.clj | 27 ++++++++++++++++++++++ .../clojure/test/tw/weekly/c82_test.clj | 9 +++++++- 3 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 challenge-082/tyler-wardhaugh/clojure/src/tw/weekly/c82/t2.clj 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 index 723a65d626..aa30c7428f 100644 --- a/challenge-082/tyler-wardhaugh/clojure/src/tw/weekly/c82/core.clj +++ b/challenge-082/tyler-wardhaugh/clojure/src/tw/weekly/c82/core.clj @@ -1,9 +1,12 @@ (ns tw.weekly.c82.core - (:require [tw.weekly.c82.t1 :as t1]) - (:gen-class)) + (:require [tw.weekly.c82.t1 :as t1]) + (:require [tw.weekly.c82.t2 :as t2]) + (:gen-class)) (defn -main "Run all tasks" [& _] (println "Task #1") - (t1/-main)) + (t1/-main) + (println "Task #2") + (t2/-main)) diff --git a/challenge-082/tyler-wardhaugh/clojure/src/tw/weekly/c82/t2.clj b/challenge-082/tyler-wardhaugh/clojure/src/tw/weekly/c82/t2.clj new file mode 100644 index 0000000000..0e397776b6 --- /dev/null +++ b/challenge-082/tyler-wardhaugh/clojure/src/tw/weekly/c82/t2.clj @@ -0,0 +1,27 @@ +(ns tw.weekly.c82.t2) + +;;; Task description for TASK #2 › Interleave String +; Submitted by: Mohammad S Anwar +; You are given 3 strings; $A, $B and $C. +; +; Write a script to check if $C is created by interleave $A and $B. +; +; Print 1 if check is success otherwise 0. +;;; + +(defn interleave-strings + "Determine if a and b can be interleaved to form c." + [a b c] + (cond (every? empty? [a b c]) true + (not= (+ (count a) (count b)) (count c)) false + :else + (let [[[ah at] [bh bt] [ch ct]] (map (juxt first rest) [a b c])] + (or (and (= ah ch) (interleave-strings at b ct)) + (and (= bh ch) (interleave-strings a bt ct)))))) + +(defn -main + "Run Task 2 with an input, defaulting to the example given in the task description." + [& args] + (let [[A B C] (or (some->> args (take 3)) ["XY" "X" "XXY"]) + result (interleave-strings A B C)] + (println (if result 1 0)))) 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 index 20c4ddfd5b..4bd70b00ee 100644 --- a/challenge-082/tyler-wardhaugh/clojure/test/tw/weekly/c82_test.clj +++ b/challenge-082/tyler-wardhaugh/clojure/test/tw/weekly/c82_test.clj @@ -1,8 +1,15 @@ (ns tw.weekly.c82-test (:require [clojure.test :refer [deftest is testing]] - [tw.weekly.c82.t1 :refer [common-factors]])) + [tw.weekly.c82.t1 :refer [common-factors]] + [tw.weekly.c82.t2 :refer [interleave-strings]])) (deftest task-1 (testing "Task 1, Common Factors" (is (= (common-factors 12 18) #{1 2 3 6})) (is (= (common-factors 18 23) #{1})))) + +(deftest task-2 + (testing "Task 2, Interleave String" + (is (true? (interleave-strings "XY" "X" "XXY"))) + (is (true? (interleave-strings "XXY" "XXZ" "XXXXZY"))) + (is (false? (interleave-strings "YX" "X" "XXY"))))) -- cgit