diff options
5 files changed, 26 insertions, 9 deletions
diff --git a/challenge-156/tyler-wardhaugh/clojure/README.md b/challenge-156/tyler-wardhaugh/clojure/README.md index e86eb6e777..6ccda4438f 100644 --- a/challenge-156/tyler-wardhaugh/clojure/README.md +++ b/challenge-156/tyler-wardhaugh/clojure/README.md @@ -21,9 +21,6 @@ Run Task #2: # ... or ... $ bb run task-2 N - # Alternatively, to run it via Babashka: - $ bb run task-2-bb N - Run the project's tests (which are samples from the task descriptions): $ clojure -T:build test diff --git a/challenge-156/tyler-wardhaugh/clojure/bb.edn b/challenge-156/tyler-wardhaugh/clojure/bb.edn index e21cd63a1e..8e5e3b49c6 100644 --- a/challenge-156/tyler-wardhaugh/clojure/bb.edn +++ b/challenge-156/tyler-wardhaugh/clojure/bb.edn @@ -78,6 +78,6 @@ :task (run-task-clj :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*)} } } diff --git a/challenge-156/tyler-wardhaugh/clojure/deps.edn b/challenge-156/tyler-wardhaugh/clojure/deps.edn index 616765131d..138cff091a 100644 --- a/challenge-156/tyler-wardhaugh/clojure/deps.edn +++ b/challenge-156/tyler-wardhaugh/clojure/deps.edn @@ -1,5 +1,6 @@ {:paths ["src" "resources"] - :deps {org.clojure/clojure {:mvn/version "1.11.0-rc1"}} + :deps {org.clojure/clojure {:mvn/version "1.11.0-rc1"} + org.clojure/math.combinatorics {:mvn/version "0.1.6"}} :aliases {:t1 {:main-opts ["-m" "c156.t1"]} :t2 {:main-opts ["-m" "c156.t2"]} diff --git a/challenge-156/tyler-wardhaugh/clojure/src/c156/t2.clj b/challenge-156/tyler-wardhaugh/clojure/src/c156/t2.clj index ef367a1124..1e295bf40d 100644 --- a/challenge-156/tyler-wardhaugh/clojure/src/c156/t2.clj +++ b/challenge-156/tyler-wardhaugh/clojure/src/c156/t2.clj @@ -1,7 +1,25 @@ (ns c156.t2 - (:require [clojure.pprint :refer [cl-format]])) + (:require [clojure.edn :as edn] + [clojure.math.combinatorics :as combo])) + +(def DEFAULT-INPUT [12]) + +(defn proper-divisors + [n] + (->> (range 2 n) (filter #(zero? (rem n %))))) + +(defn weird? + [n] + (let [divs (proper-divisors n)] + (and + (> (reduce + divs) n) + (not-any? + #{n} + (->> (combo/subsets divs) (map #(reduce + %))))))) (defn -main "Run Task 2 with a given input N, defaulting to the first example from the task description." - [& args]) + [& args] + (let [[N] (or (some->> args (map edn/read-string)) DEFAULT-INPUT)] + (println (if (weird? N) 1 0)))) diff --git a/challenge-156/tyler-wardhaugh/clojure/test/c156/t2_test.clj b/challenge-156/tyler-wardhaugh/clojure/test/c156/t2_test.clj index 0c8409a741..14c3bb455f 100644 --- a/challenge-156/tyler-wardhaugh/clojure/test/c156/t2_test.clj +++ b/challenge-156/tyler-wardhaugh/clojure/test/c156/t2_test.clj @@ -1,7 +1,8 @@ (ns c156.t2-test (:require [clojure.test :refer [deftest is testing]] - [c156.t2 :as t2])) + [c156.t2 :refer [weird?]])) (deftest task-2 (testing "Task 2 produces the correct result" - )) + (is (false? (weird? 12))) + (is (true? (weird? 70))))) |
