From f9482b9b1eee4938a35a455164f04a0800a1bdc0 Mon Sep 17 00:00:00 2001 From: Tyler Wardhaugh Date: Mon, 8 Nov 2021 15:37:50 -0800 Subject: Ch138 (Clojure): prep for challenge --- challenge-138/tyler-wardhaugh/clojure/README.md | 12 ++++++------ challenge-138/tyler-wardhaugh/clojure/bb.edn | 18 ++++++++++++++---- challenge-138/tyler-wardhaugh/clojure/pom.xml | 8 ++++---- .../clojure/src/tw/weekly/c138/core.clj | 12 ++++++++++++ .../tyler-wardhaugh/clojure/src/tw/weekly/c138/t1.clj | 14 ++++++++++++++ .../tyler-wardhaugh/clojure/src/tw/weekly/c138/t2.clj | 14 ++++++++++++++ .../clojure/test/tw/weekly/c138/t1_test.clj | 7 +++++++ .../clojure/test/tw/weekly/c138/t2_test.clj | 7 +++++++ 8 files changed, 78 insertions(+), 14 deletions(-) create mode 100644 challenge-138/tyler-wardhaugh/clojure/src/tw/weekly/c138/core.clj create mode 100644 challenge-138/tyler-wardhaugh/clojure/src/tw/weekly/c138/t1.clj create mode 100644 challenge-138/tyler-wardhaugh/clojure/src/tw/weekly/c138/t2.clj create mode 100644 challenge-138/tyler-wardhaugh/clojure/test/tw/weekly/c138/t1_test.clj create mode 100644 challenge-138/tyler-wardhaugh/clojure/test/tw/weekly/c138/t2_test.clj diff --git a/challenge-138/tyler-wardhaugh/clojure/README.md b/challenge-138/tyler-wardhaugh/clojure/README.md index 371f142e4e..7d1b854cdc 100644 --- a/challenge-138/tyler-wardhaugh/clojure/README.md +++ b/challenge-138/tyler-wardhaugh/clojure/README.md @@ -1,7 +1,7 @@ -# tw.weekly.c137 +# tw.weekly.c138 -The Weekly Challenge - #137 - Tyler Wardhaugh +The Weekly Challenge - #138 - 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.c137.core + $ clojure -M -m tw.weekly.c138.core # ... or ... $ bb run both @@ -21,13 +21,13 @@ Run the project's tests (which are samples from the task descriptions): Run Task #1 with input - $ clojure -M -m tw.weekly.c137.t1 + $ clojure -M -m tw.weekly.c138.t1 N # ... or ... - $ bb run task-1 + $ bb run task-1 N Run Task #2 with input: - $ clojure -M -m tw.weekly.c137.t2 N + $ clojure -M -m tw.weekly.c138.t2 N # ... or ... $ bb run task-2 N diff --git a/challenge-138/tyler-wardhaugh/clojure/bb.edn b/challenge-138/tyler-wardhaugh/clojure/bb.edn index f0892047d3..be8af5209b 100644 --- a/challenge-138/tyler-wardhaugh/clojure/bb.edn +++ b/challenge-138/tyler-wardhaugh/clojure/bb.edn @@ -30,7 +30,17 @@ ([task args] (run-task-bb task args (get-task-ns task))) ([task args task-ns] (let [bb-cmd (format "bb -m %s " task-ns)] - (apply shell bb-cmd args))))) + (apply shell bb-cmd args)))) + + (defn bb-no-go + [task & _] + (binding [*out* *err*] + (let [task-num (-> task name last (Character/digit 10))] + (println + (str "error: can't run Task " task-num + " via Babashka because it depends" + " on some incompatible libraries.")))) + (System/exit 1))) clean {:doc "Clean out temporary files" :task (run! fs/delete-tree @@ -63,16 +73,16 @@ c**** {:doc "CHALLENGE TASKS"} task-1 {:doc "Run Task 1 (via clojure)" - :task (run-task :t1 *command-line-args* "tw.weekly.c137.t1")} + :task (run-task :t1 *command-line-args*)} task-1-bb {:doc "Run Task 1 (via Babashka)" - :task (run-task-bb :t1 *command-line-args* "tw.weekly.c137.t1")} + :task (bb-no-go :t1 *command-line-args*)} task-2 {:doc "Run Task 2 (via clojure)" :task (run-task :t2 *command-line-args*)} task-2-bb {:doc "Run Task 2 (via Babashka)" - :task (run-task-bb :t2 *command-line-args*)} + :task (bb-no-go :t2 *command-line-args*)} both {:doc "Run both tasks (via clojure)" :task (do diff --git a/challenge-138/tyler-wardhaugh/clojure/pom.xml b/challenge-138/tyler-wardhaugh/clojure/pom.xml index 03a691f300..2a0300d875 100644 --- a/challenge-138/tyler-wardhaugh/clojure/pom.xml +++ b/challenge-138/tyler-wardhaugh/clojure/pom.xml @@ -2,11 +2,11 @@ 4.0.0 tw.weekly - tw.weekly.c137 + tw.weekly.c138 0.1.0-SNAPSHOT - tw.weekly.c137 - Challenge #137 - https://github.com/tw.weekly/tw.weekly.c137 + tw.weekly.c138 + Challenge #138 + https://github.com/tw.weekly/tw.weekly.c138 Eclipse Public License diff --git a/challenge-138/tyler-wardhaugh/clojure/src/tw/weekly/c138/core.clj b/challenge-138/tyler-wardhaugh/clojure/src/tw/weekly/c138/core.clj new file mode 100644 index 0000000000..403661d6f1 --- /dev/null +++ b/challenge-138/tyler-wardhaugh/clojure/src/tw/weekly/c138/core.clj @@ -0,0 +1,12 @@ +(ns tw.weekly.c138.core + (:require [tw.weekly.c138.t1 :as t1]) + (:require [tw.weekly.c138.t2 :as t2]) + (:gen-class)) + +(defn -main + "Run all tasks" + [& _] + (println "Task #1:") + (t1/-main) + (println "\nTask #2:") + (t2/-main)) diff --git a/challenge-138/tyler-wardhaugh/clojure/src/tw/weekly/c138/t1.clj b/challenge-138/tyler-wardhaugh/clojure/src/tw/weekly/c138/t1.clj new file mode 100644 index 0000000000..badf10ee50 --- /dev/null +++ b/challenge-138/tyler-wardhaugh/clojure/src/tw/weekly/c138/t1.clj @@ -0,0 +1,14 @@ +(ns tw.weekly.c138.t1 + (:require [clojure.edn :as edn])) + +;;; +; Task description for TASK #1 › Workdays +;;; +(def DEFAULT-INPUT [2021]) + +(defn -main + "Run Task 2 with a given input N, defaulting to the first example from the + task description." + [& args] + (let [[N] (or (some->> args (map edn/read-string)) DEFAULT-INPUT)] + )) diff --git a/challenge-138/tyler-wardhaugh/clojure/src/tw/weekly/c138/t2.clj b/challenge-138/tyler-wardhaugh/clojure/src/tw/weekly/c138/t2.clj new file mode 100644 index 0000000000..ca4530b799 --- /dev/null +++ b/challenge-138/tyler-wardhaugh/clojure/src/tw/weekly/c138/t2.clj @@ -0,0 +1,14 @@ +(ns tw.weekly.c138.t2 + (:require [clojure.edn :as edn])) + +;;; +; Task description for TASK #2 › Split Number +;;; +(def DEFAULT-INPUT [81]) + +(defn -main + "Run Task 2 with a given input N, defaulting to the first example from the + task description." + [& args] + (let [[N] (or (some->> args (map edn/read-string)) DEFAULT-INPUT)] + )) diff --git a/challenge-138/tyler-wardhaugh/clojure/test/tw/weekly/c138/t1_test.clj b/challenge-138/tyler-wardhaugh/clojure/test/tw/weekly/c138/t1_test.clj new file mode 100644 index 0000000000..8809fb615c --- /dev/null +++ b/challenge-138/tyler-wardhaugh/clojure/test/tw/weekly/c138/t1_test.clj @@ -0,0 +1,7 @@ +(ns tw.weekly.c138.t1-test + (:require [clojure.test :refer [deftest is testing]] + [tw.weekly.c138.t1 :refer []])) + +(deftest examples + (testing "Examples from description" + )) diff --git a/challenge-138/tyler-wardhaugh/clojure/test/tw/weekly/c138/t2_test.clj b/challenge-138/tyler-wardhaugh/clojure/test/tw/weekly/c138/t2_test.clj new file mode 100644 index 0000000000..71d2fe47e4 --- /dev/null +++ b/challenge-138/tyler-wardhaugh/clojure/test/tw/weekly/c138/t2_test.clj @@ -0,0 +1,7 @@ +(ns tw.weekly.c138.t2-test + (:require [clojure.test :refer [deftest is testing]] + [tw.weekly.c138.t2 :refer []])) + +(deftest examples + (testing "Examples from description" + )) -- cgit