diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-10-14 03:02:24 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-14 03:02:24 +0100 |
| commit | cc85ac91d445a9e4ac1e034b758db37a5ea23d50 (patch) | |
| tree | 18810ff7b141abd537d4f348d8c75fcb825191c0 | |
| parent | 378fea5d4e7e7efd375bb32f1295140f7e83f6f7 (diff) | |
| parent | c0bc7cca5b312832af50c6f03dac2565b58bac4c (diff) | |
| download | perlweeklychallenge-club-cc85ac91d445a9e4ac1e034b758db37a5ea23d50.tar.gz perlweeklychallenge-club-cc85ac91d445a9e4ac1e034b758db37a5ea23d50.tar.bz2 perlweeklychallenge-club-cc85ac91d445a9e4ac1e034b758db37a5ea23d50.zip | |
Merge pull request #2516 from tylerw/tw/challenge-082
Challenge 082
7 files changed, 93 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 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>tw.weekly</groupId> - <artifactId>tw.weekly.c81</artifactId> + <artifactId>tw.weekly.c82</artifactId> <version>0.1.0-SNAPSHOT</version> - <name>tw.weekly.c81</name> - <description>Challenge #081</description> - <url>https://github.com/tw.weekly/tw.weekly.c81</url> + <name>tw.weekly.c82</name> + <description>Challenge #082</description> + <url>https://github.com/tw.weekly/tw.weekly.c82</url> <licenses> <license> <name>Eclipse Public License</name> @@ -19,9 +19,9 @@ </developer> </developers> <scm> - <url>https://github.com/tw.weekly/tw.weekly.c81</url> - <connection>scm:git:git://github.com/tw.weekly/tw.weekly.c81.git</connection> - <developerConnection>scm:git:ssh://git@github.com/tw.weekly/tw.weekly.c81.git</developerConnection> + <url>https://github.com/tw.weekly/tw.weekly.c82</url> + <connection>scm:git:git://github.com/tw.weekly/tw.weekly.c82.git</connection> + <developerConnection>scm:git:ssh://git@github.com/tw.weekly/tw.weekly.c82.git</developerConnection> <tag>HEAD</tag> </scm> <dependencies> @@ -30,11 +30,6 @@ <artifactId>clojure</artifactId> <version>1.10.1</version> </dependency> - <dependency> - <groupId>net.cgrand</groupId> - <artifactId>xforms</artifactId> - <version>0.19.2</version> - </dependency> </dependencies> <build> <sourceDirectory>src</sourceDirectory> 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..aa30c7428f --- /dev/null +++ b/challenge-082/tyler-wardhaugh/clojure/src/tw/weekly/c82/core.clj @@ -0,0 +1,12 @@ +(ns tw.weekly.c82.core + (: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) + (println "Task #2") + (t2/-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/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 new file mode 100644 index 0000000000..4bd70b00ee --- /dev/null +++ b/challenge-082/tyler-wardhaugh/clojure/test/tw/weekly/c82_test.clj @@ -0,0 +1,15 @@ +(ns tw.weekly.c82-test + (:require [clojure.test :refer [deftest is testing]] + [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"))))) |
