diff options
| author | Tyler Wardhaugh <tyler.wardhaugh@gmail.com> | 2021-11-19 16:32:32 -0800 |
|---|---|---|
| committer | Tyler Wardhaugh <tyler.wardhaugh@gmail.com> | 2021-11-21 07:54:29 -0800 |
| commit | d4af8e63ed8bb83070c498dc3b8fd874ad19e438 (patch) | |
| tree | fcd2c3a5b1651615d08ca4e28abfd20c5d34a9f7 | |
| parent | 16d51d568913a4e45f0cbd61f3150213c2f82257 (diff) | |
| download | perlweeklychallenge-club-d4af8e63ed8bb83070c498dc3b8fd874ad19e438.tar.gz perlweeklychallenge-club-d4af8e63ed8bb83070c498dc3b8fd874ad19e438.tar.bz2 perlweeklychallenge-club-d4af8e63ed8bb83070c498dc3b8fd874ad19e438.zip | |
Ch139 (Clojure): Task 1
3 files changed, 26 insertions, 3 deletions
diff --git a/challenge-139/tyler-wardhaugh/clojure/bb.edn b/challenge-139/tyler-wardhaugh/clojure/bb.edn index be8af5209b..ec79e59292 100644 --- a/challenge-139/tyler-wardhaugh/clojure/bb.edn +++ b/challenge-139/tyler-wardhaugh/clojure/bb.edn @@ -76,7 +76,7 @@ :task (run-task :t1 *command-line-args*)} task-1-bb {:doc "Run Task 1 (via Babashka)" - :task (bb-no-go :t1 *command-line-args*)} + :task (run-task-bb :t1 *command-line-args*)} task-2 {:doc "Run Task 2 (via clojure)" :task (run-task :t2 *command-line-args*)} diff --git a/challenge-139/tyler-wardhaugh/clojure/src/tw/weekly/c139/t1.clj b/challenge-139/tyler-wardhaugh/clojure/src/tw/weekly/c139/t1.clj index ae49c2aea9..532e227a7c 100644 --- a/challenge-139/tyler-wardhaugh/clojure/src/tw/weekly/c139/t1.clj +++ b/challenge-139/tyler-wardhaugh/clojure/src/tw/weekly/c139/t1.clj @@ -6,9 +6,20 @@ ;;; (def DEFAULT-INPUT [[1 2 3 4 5]]) +(defn ordered? + [coll] + (or (empty? coll) (apply <= coll))) + +(defn shortcircuiting-ordered? + [coll] + (or (empty? coll) + (-> (when-let [[x & xs] coll] + (reduce (fn [p c] (if (<= p c) c (reduced false))) x xs)) + boolean))) + (defn -main "Run Task 3 with a given input COLL, defaulting to the first example from the task description." [& args] (let [[COLL] (or (some->> args (map edn/read-string)) DEFAULT-INPUT)] - )) + (println (if (shortcircuiting-ordered? COLL) 1 0)))) diff --git a/challenge-139/tyler-wardhaugh/clojure/test/tw/weekly/c139/t1_test.clj b/challenge-139/tyler-wardhaugh/clojure/test/tw/weekly/c139/t1_test.clj index ba540d150e..cddc4fa860 100644 --- a/challenge-139/tyler-wardhaugh/clojure/test/tw/weekly/c139/t1_test.clj +++ b/challenge-139/tyler-wardhaugh/clojure/test/tw/weekly/c139/t1_test.clj @@ -1,3 +1,15 @@ (ns tw.weekly.c139.t1-test (:require [clojure.test :refer [deftest is testing]] - [tw.weekly.c139.t1 :refer []])) + [tw.weekly.c139.t1 :refer [ordered? shortcircuiting-ordered?]])) + +(def both (juxt ordered? shortcircuiting-ordered?)) + +(deftest examples + (testing "Examples from description" + (is (every? true? (both [1 2 3 4 5]))) + (is (every? false? (both [1 3 2 4 5]))))) + +(deftest more + (testing "More interesting tests" + (is (every? true? (both [1]))) + (is (every? true? (both []))))) |
