From fa5731052dcccec7fd0c77d96266690d2841b815 Mon Sep 17 00:00:00 2001 From: Tyler Wardhaugh Date: Mon, 7 Dec 2020 12:06:06 -0800 Subject: Ch90: prep for challenge --- challenge-090/tyler-wardhaugh/clojure/README.md | 10 +++++----- challenge-090/tyler-wardhaugh/clojure/deps.edn | 10 +++------- challenge-090/tyler-wardhaugh/clojure/pom.xml | 24 +++++++----------------- 3 files changed, 15 insertions(+), 29 deletions(-) (limited to 'challenge-090/tyler-wardhaugh/clojure') 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 @@ 4.0.0 tw.weekly - tw.weekly.c89 + tw.weekly.c90 0.1.0-SNAPSHOT - tw.weekly.c89 - Challenge #089 - https://github.com/tw.weekly/tw.weekly.c89 + tw.weekly.c90 + Challenge #090 + https://github.com/tw.weekly/tw.weekly.c90 Eclipse Public License @@ -19,9 +19,9 @@ - https://github.com/tw.weekly/tw.weekly.c89 - scm:git:git://github.com/tw.weekly/tw.weekly.c89.git - scm:git:ssh://git@github.com/tw.weekly/tw.weekly.c89.git + https://github.com/tw.weekly/tw.weekly.c90 + scm:git:git://github.com/tw.weekly/tw.weekly.c90.git + scm:git:ssh://git@github.com/tw.weekly/tw.weekly.c90.git HEAD @@ -30,16 +30,6 @@ clojure 1.10.1 - - net.mikera - core.matrix - 0.62.0 - - - org.clojure - math.numeric-tower - 0.0.4 - src -- cgit From 085764e526d26c50a09a2c0c18da809268e32f33 Mon Sep 17 00:00:00 2001 From: Tyler Wardhaugh Date: Mon, 7 Dec 2020 12:39:22 -0800 Subject: Ch90 (Clojure): Task 1 & Task 2 --- .../clojure/src/tw/weekly/c90/core.clj | 12 ++++++++++ .../clojure/src/tw/weekly/c90/t1.clj | 28 ++++++++++++++++++++++ .../clojure/src/tw/weekly/c90/t2.clj | 22 +++++++++++++++++ .../clojure/test/tw/weekly/c90_test.clj | 16 +++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 challenge-090/tyler-wardhaugh/clojure/src/tw/weekly/c90/core.clj create mode 100644 challenge-090/tyler-wardhaugh/clojure/src/tw/weekly/c90/t1.clj create mode 100644 challenge-090/tyler-wardhaugh/clojure/src/tw/weekly/c90/t2.clj create mode 100644 challenge-090/tyler-wardhaugh/clojure/test/tw/weekly/c90_test.clj (limited to 'challenge-090/tyler-wardhaugh/clojure') 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))))) -- cgit