diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-11-26 10:35:20 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-26 10:35:20 +0000 |
| commit | 83a289ba2d08515dd1be9596ac461f9c100a2bc2 (patch) | |
| tree | 4385c38b5c73e0a9ec0e3396fa0477bde39a7920 | |
| parent | 997646c13451c37947d988d1ef2441b44dbeff35 (diff) | |
| parent | 47c7c038c04618222b67439d9bbe7e482ef3b3f2 (diff) | |
| download | perlweeklychallenge-club-83a289ba2d08515dd1be9596ac461f9c100a2bc2.tar.gz perlweeklychallenge-club-83a289ba2d08515dd1be9596ac461f9c100a2bc2.tar.bz2 perlweeklychallenge-club-83a289ba2d08515dd1be9596ac461f9c100a2bc2.zip | |
Merge pull request #5281 from tylerw/tw/challenge-140
Challenge 140
9 files changed, 91 insertions, 14 deletions
diff --git a/challenge-140/tyler-wardhaugh/clojure/README.md b/challenge-140/tyler-wardhaugh/clojure/README.md index 17ac43fedd..213f1884bc 100644 --- a/challenge-140/tyler-wardhaugh/clojure/README.md +++ b/challenge-140/tyler-wardhaugh/clojure/README.md @@ -1,7 +1,7 @@ -# tw.weekly.c139 +# tw.weekly.c140 -The Weekly Challenge - #139 - Tyler Wardhaugh +The Weekly Challenge - #140 - Tyler Wardhaugh ## Usage @@ -9,7 +9,7 @@ Clojure ([installation instructions](https://clojure.org/guides/getting_started# Run the project directly (shows default output from both tasks): - $ clojure -M -m tw.weekly.c139.core + $ clojure -M -m tw.weekly.c140.core # ... or ... $ bb run both @@ -21,15 +21,15 @@ Run the project's tests (which are samples from the task descriptions): Run Task #1 with input - $ clojure -M -m tw.weekly.c139.t1 COLL + $ clojure -M -m tw.weekly.c140.t1 A B # ... or ... - $ bb run task-1 COLL + $ bb run task-1 A B Run Task #2 with input: - $ clojure -M -m tw.weekly.c139.t2 + $ clojure -M -m tw.weekly.c140.t2 I J K # ... or ... - $ bb run task-2 + $ bb run task-2 I J K View available tasks Babashka can run: diff --git a/challenge-140/tyler-wardhaugh/clojure/bb.edn b/challenge-140/tyler-wardhaugh/clojure/bb.edn index ec79e59292..e053ec5de1 100644 --- a/challenge-140/tyler-wardhaugh/clojure/bb.edn +++ b/challenge-140/tyler-wardhaugh/clojure/bb.edn @@ -82,7 +82,7 @@ :task (run-task :t2 *command-line-args*)} task-2-bb {:doc "Run Task 2 (via Babashka)" - :task (bb-no-go :t2 *command-line-args*)} + :task (run-task-bb :t2 *command-line-args*)} both {:doc "Run both tasks (via clojure)" :task (do diff --git a/challenge-140/tyler-wardhaugh/clojure/deps.edn b/challenge-140/tyler-wardhaugh/clojure/deps.edn index 3386938e59..5b1400b27e 100644 --- a/challenge-140/tyler-wardhaugh/clojure/deps.edn +++ b/challenge-140/tyler-wardhaugh/clojure/deps.edn @@ -1,6 +1,5 @@ {:paths ["src" "resources"] - :deps {org.clojure/clojure {:mvn/version "1.10.3"} - com.hypirion/primes {:mvn/version "0.2.2"}} + :deps {org.clojure/clojure {:mvn/version "1.10.3"}} :aliases {:test {:extra-paths ["test"] :extra-deps {org.clojure/test.check {:mvn/version "1.1.0"} diff --git a/challenge-140/tyler-wardhaugh/clojure/pom.xml b/challenge-140/tyler-wardhaugh/clojure/pom.xml index 66472e6504..e51de32ab2 100644 --- a/challenge-140/tyler-wardhaugh/clojure/pom.xml +++ b/challenge-140/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.c139</artifactId> + <artifactId>tw.weekly.c140</artifactId> <version>0.1.0-SNAPSHOT</version> - <name>tw.weekly.c139</name> - <description>Challenge #139</description> - <url>https://github.com/tw.weekly/tw.weekly.c139</url> + <name>tw.weekly.c140</name> + <description>Challenge #140</description> + <url>https://github.com/tw.weekly/tw.weekly.c140</url> <licenses> <license> <name>Eclipse Public License</name> diff --git a/challenge-140/tyler-wardhaugh/clojure/src/tw/weekly/c140/core.clj b/challenge-140/tyler-wardhaugh/clojure/src/tw/weekly/c140/core.clj new file mode 100644 index 0000000000..7ac37537e6 --- /dev/null +++ b/challenge-140/tyler-wardhaugh/clojure/src/tw/weekly/c140/core.clj @@ -0,0 +1,12 @@ +(ns tw.weekly.c140.core + (:require [tw.weekly.c140.t1 :as t1]) + (:require [tw.weekly.c140.t2 :as t2]) + (:gen-class)) + +(defn -main + "Run all tasks" + [& _] + (println "Task #1:") + (t1/-main) + (println "\nTask #2:") + (t2/-main)) diff --git a/challenge-140/tyler-wardhaugh/clojure/src/tw/weekly/c140/t1.clj b/challenge-140/tyler-wardhaugh/clojure/src/tw/weekly/c140/t1.clj new file mode 100644 index 0000000000..8de084f8c1 --- /dev/null +++ b/challenge-140/tyler-wardhaugh/clojure/src/tw/weekly/c140/t1.clj @@ -0,0 +1,27 @@ +(ns tw.weekly.c140.t1) + +;;; +; Task description for TASK #1 › Add Binary +;;; +(def DEFAULT-INPUT ["11" "1"]) + +(defn binstr->num + [s] + (Long/parseLong s 2)) + +(defn num->binstr + [n] + (Long/toString n 2)) + +(defn add-binary + [& binstrs] + (->> binstrs + (transduce (map binstr->num) +) + num->binstr)) + +(defn -main + "Run Task 1 with a given input A B, defaulting to the first example from the + task description." + [& args] + (let [[A B] (or args DEFAULT-INPUT)] + (println (add-binary A B)))) diff --git a/challenge-140/tyler-wardhaugh/clojure/src/tw/weekly/c140/t2.clj b/challenge-140/tyler-wardhaugh/clojure/src/tw/weekly/c140/t2.clj new file mode 100644 index 0000000000..940fe5d069 --- /dev/null +++ b/challenge-140/tyler-wardhaugh/clojure/src/tw/weekly/c140/t2.clj @@ -0,0 +1,22 @@ +(ns tw.weekly.c140.t2 + (:require [clojure.edn :as edn])) + +;;; +; Task description for TASK #2 › Multiplication Table +;;; +(def DEFAULT-INPUT [2 3 4]) + +(defn get-kth-in-multi + [i j k] + (-> (for [i (range 1 (inc i)) + j (range 1 (inc j))] + (* i j)) + sort + (nth (dec k)))) + +(defn -main + "Run Task 2 with a given input I J K, defaulting to the first example from + the task description." + [& args] + (let [[I J K] (or (some->> args (map edn/read-string)) DEFAULT-INPUT)] + (println (get-kth-in-multi I J K)))) diff --git a/challenge-140/tyler-wardhaugh/clojure/test/tw/weekly/c140/t1_test.clj b/challenge-140/tyler-wardhaugh/clojure/test/tw/weekly/c140/t1_test.clj new file mode 100644 index 0000000000..93d9b2b9de --- /dev/null +++ b/challenge-140/tyler-wardhaugh/clojure/test/tw/weekly/c140/t1_test.clj @@ -0,0 +1,9 @@ +(ns tw.weekly.c140.t1-test + (:require [clojure.test :refer [deftest is testing]] + [tw.weekly.c140.t1 :refer [add-binary]])) + +(deftest examples + (testing "Examples from description" + (is (= "100" (add-binary "11" "1"))) + (is (= "110" (add-binary "101" "1"))) + (is (= "111" (add-binary "100" "11"))))) diff --git a/challenge-140/tyler-wardhaugh/clojure/test/tw/weekly/c140/t2_test.clj b/challenge-140/tyler-wardhaugh/clojure/test/tw/weekly/c140/t2_test.clj new file mode 100644 index 0000000000..2f41471ce8 --- /dev/null +++ b/challenge-140/tyler-wardhaugh/clojure/test/tw/weekly/c140/t2_test.clj @@ -0,0 +1,8 @@ +(ns tw.weekly.c140.t2-test + (:require [clojure.test :refer [deftest is testing]] + [tw.weekly.c140.t2 :refer [get-kth-in-multi]])) + +(deftest examples + (testing "Examples from description" + (is (= 3 (get-kth-in-multi 2 3 4))) + (is (= 4 (get-kth-in-multi 3 3 6))))) |
