diff options
| author | Luis Mochan <mochan@fis.unam.mx> | 2020-12-09 12:36:23 -0600 |
|---|---|---|
| committer | Luis Mochan <mochan@fis.unam.mx> | 2020-12-09 12:36:23 -0600 |
| commit | da971e8987ceade04a6eecbe59efd44b7e9dffb1 (patch) | |
| tree | 073bb8527dc39be46412e02e739131f1c613cc7b /challenge-090/tyler-wardhaugh/clojure | |
| parent | b656bc813129c410b0ccd81449a55222a4f8dcc6 (diff) | |
| parent | 931e28a9fe63ad0942cf9f3099191a0e21a978c2 (diff) | |
| download | perlweeklychallenge-club-da971e8987ceade04a6eecbe59efd44b7e9dffb1.tar.gz perlweeklychallenge-club-da971e8987ceade04a6eecbe59efd44b7e9dffb1.tar.bz2 perlweeklychallenge-club-da971e8987ceade04a6eecbe59efd44b7e9dffb1.zip | |
Merge branch 'master' of github.com:manwar/perlweeklychallenge-club
Diffstat (limited to 'challenge-090/tyler-wardhaugh/clojure')
7 files changed, 93 insertions, 29 deletions
diff --git a/challenge-090/tyler-wardhaugh/clojure/README.md b/challenge-090/tyler-wardhaugh/clojure/README.md index f5a89af18d..41000b8199 100644 --- a/challenge-090/tyler-wardhaugh/clojure/README.md +++ b/challenge-090/tyler-wardhaugh/clojure/README.md @@ -1,13 +1,13 @@ -# tw.weekly.c89 +# tw.weekly.c90 -The Weekly Challenge - #089 - Tyler Wardhaugh +The Weekly Challenge - #090 - Tyler Wardhaugh ## Usage Run the project directly (shows default output from both tasks): - $ clojure -M -m tw.weekly.c89.core + $ clojure -M -m tw.weekly.c90.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.c89.t1 N + $ clojure -M -m tw.weekly.c90.t1 DNA Run Task #2: - $ clojure -M -m tw.weekly.c89.t2 + $ clojure -M -m tw.weekly.c90.t2 A B ## Project Template diff --git a/challenge-090/tyler-wardhaugh/clojure/deps.edn b/challenge-090/tyler-wardhaugh/clojure/deps.edn index cfd5d782d1..1fae9ef933 100644 --- a/challenge-090/tyler-wardhaugh/clojure/deps.edn +++ b/challenge-090/tyler-wardhaugh/clojure/deps.edn @@ -1,9 +1,5 @@ {:paths ["src" "resources"] - :deps {org.clojure/clojure {:mvn/version "1.10.1"} - org.clojure/core.logic {:mvn/version "1.0.0"} - org.clojure/math.combinatorics {:mvn/version "0.1.6"} - org.clojure/math.numeric-tower {:mvn/version "0.0.4"} - org.clojure/tools.macro {:mvn/version "0.1.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"}}} @@ -14,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.c88.jar" - "-C" "-m" "tw.weekly.c88"]}}} + :main-opts ["-m" "hf.depstar.uberjar" "tw.weekly.c90.jar" + "-C" "-m" "tw.weekly.c90"]}}} diff --git a/challenge-090/tyler-wardhaugh/clojure/pom.xml b/challenge-090/tyler-wardhaugh/clojure/pom.xml index 3097f51f8e..bc8a82e4cd 100644 --- a/challenge-090/tyler-wardhaugh/clojure/pom.xml +++ b/challenge-090/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.c89</artifactId> + <artifactId>tw.weekly.c90</artifactId> <version>0.1.0-SNAPSHOT</version> - <name>tw.weekly.c89</name> - <description>Challenge #089</description> - <url>https://github.com/tw.weekly/tw.weekly.c89</url> + <name>tw.weekly.c90</name> + <description>Challenge #090</description> + <url>https://github.com/tw.weekly/tw.weekly.c90</url> <licenses> <license> <name>Eclipse Public License</name> @@ -19,9 +19,9 @@ </developer> </developers> <scm> - <url>https://github.com/tw.weekly/tw.weekly.c89</url> - <connection>scm:git:git://github.com/tw.weekly/tw.weekly.c89.git</connection> - <developerConnection>scm:git:ssh://git@github.com/tw.weekly/tw.weekly.c89.git</developerConnection> + <url>https://github.com/tw.weekly/tw.weekly.c90</url> + <connection>scm:git:git://github.com/tw.weekly/tw.weekly.c90.git</connection> + <developerConnection>scm:git:ssh://git@github.com/tw.weekly/tw.weekly.c90.git</developerConnection> <tag>HEAD</tag> </scm> <dependencies> @@ -30,16 +30,6 @@ <artifactId>clojure</artifactId> <version>1.10.1</version> </dependency> - <dependency> - <groupId>net.mikera</groupId> - <artifactId>core.matrix</artifactId> - <version>0.62.0</version> - </dependency> - <dependency> - <groupId>org.clojure</groupId> - <artifactId>math.numeric-tower</artifactId> - <version>0.0.4</version> - </dependency> </dependencies> <build> <sourceDirectory>src</sourceDirectory> diff --git a/challenge-090/tyler-wardhaugh/clojure/src/tw/weekly/c90/core.clj b/challenge-090/tyler-wardhaugh/clojure/src/tw/weekly/c90/core.clj new file mode 100644 index 0000000000..296c2c6051 --- /dev/null +++ b/challenge-090/tyler-wardhaugh/clojure/src/tw/weekly/c90/core.clj @@ -0,0 +1,12 @@ +(ns tw.weekly.c90.core + (:require [tw.weekly.c90.t1 :as t1]) + (:require [tw.weekly.c90.t2 :as t2]) + (:gen-class)) + +(defn -main + "Run all tasks" + [& _] + (println "Task #1:") + (t1/-main) + (println "\nTask #2:") + (t2/-main)) diff --git a/challenge-090/tyler-wardhaugh/clojure/src/tw/weekly/c90/t1.clj b/challenge-090/tyler-wardhaugh/clojure/src/tw/weekly/c90/t1.clj new file mode 100644 index 0000000000..e739241345 --- /dev/null +++ b/challenge-090/tyler-wardhaugh/clojure/src/tw/weekly/c90/t1.clj @@ -0,0 +1,28 @@ +(ns tw.weekly.c90.t1 + (:require [clojure.string :as str]) + (:require [clojure.pprint :refer [cl-format]]) + (:require [clojure.edn :as edn])) + +;;; +; Task description for TASK #1 › DNA Sequence +;;; + +(def DEFAULT-DNA + "GTAAACCCCTTTTCATTTAGACAGATCGACTCCTTATCCATTCTCAGAGATGTGTTGCTGGTCGCCG") + +(defn process-dna + "Process the DNA sequence, counting nucleiobases and determining the + complementary sequence." + [dna] + (let [complement-dna (fn [s] (str/escape s {\T \A, \A \T, \C \G, \G \C}))] + ((juxt frequencies complement-dna) dna))) + +(defn -main + "Run Task 1 with a given DNA sequence, defaulting to the example given in + the task description." + [& args] + (let [dna (or (some-> args first edn/read-string) DEFAULT-DNA) + [freqs complement-seq] (process-dna dna)] + (cl-format true "~12a: ~a~%~12a: ~a~%" + "Counts" freqs + "Complement" complement-seq))) diff --git a/challenge-090/tyler-wardhaugh/clojure/src/tw/weekly/c90/t2.clj b/challenge-090/tyler-wardhaugh/clojure/src/tw/weekly/c90/t2.clj new file mode 100644 index 0000000000..ab767f91fc --- /dev/null +++ b/challenge-090/tyler-wardhaugh/clojure/src/tw/weekly/c90/t2.clj @@ -0,0 +1,22 @@ +(ns tw.weekly.c90.t2 + (:require [clojure.edn :as edn])) + +;;; +; Task description for TASK #2 › Ethiopian Multiplication +;;; + +(defn ethiopian-multiply + "Compute the product of two positive integers using Ethiopian Multiplication." + [a b] + (let [source (map vector (iterate #(quot % 2) a) (iterate #(* 2 %) b)) + xf (comp + (take-while (fn [[a _]] (pos? a))) + (keep (fn [[a b]] (when (odd? a) b))))] + (transduce xf + source))) + +(defn -main + "Run Task 2 with the given positive integers, defaulting to the example + given in the explanation page linked from the task description." + [& args] + (let [[A B] (or (some->> args (take 2) (map edn/read-string)) [12 14])] + (println (ethiopian-multiply A B)))) diff --git a/challenge-090/tyler-wardhaugh/clojure/test/tw/weekly/c90_test.clj b/challenge-090/tyler-wardhaugh/clojure/test/tw/weekly/c90_test.clj new file mode 100644 index 0000000000..a09788f137 --- /dev/null +++ b/challenge-090/tyler-wardhaugh/clojure/test/tw/weekly/c90_test.clj @@ -0,0 +1,16 @@ +(ns tw.weekly.c90-test + (:require [clojure.test :refer [deftest is testing]] + [tw.weekly.c90.t1 :refer [DEFAULT-DNA process-dna]] + [tw.weekly.c90.t2 :refer [ethiopian-multiply]])) + +(def COMPLEMENT-DEFAULT-DNA + "CATTTGGGGAAAAGTAAATCTGTCTAGCTGAGGAATAGGTAAGAGTCTCTACACAACGACCAGCGGC") + +(deftest task-1 + (testing "Task 1, DNA Sequence" + (is (= [{\G 13, \T 22, \A 14, \C 18}, COMPLEMENT-DEFAULT-DNA] + (process-dna DEFAULT-DNA))))) + +(deftest task-2 + (testing "Task 2, Ethiopian Multiplication" + (is (= 168 (ethiopian-multiply 12 14))))) |
