diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-09-29 06:43:14 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-09-29 06:43:14 +0100 |
| commit | 07c8ff0f43c1168cce222b3e3d1c9665dd1c3c2e (patch) | |
| tree | 5f5594ff0981819d7739d23d4ffa0eda946f9afa /challenge-080 | |
| parent | c147375328add59f6c997ed237214fcfbdb18560 (diff) | |
| parent | 3db826ef9f6b2b73586d75f7b89c010a079c40a5 (diff) | |
| download | perlweeklychallenge-club-07c8ff0f43c1168cce222b3e3d1c9665dd1c3c2e.tar.gz perlweeklychallenge-club-07c8ff0f43c1168cce222b3e3d1c9665dd1c3c2e.tar.bz2 perlweeklychallenge-club-07c8ff0f43c1168cce222b3e3d1c9665dd1c3c2e.zip | |
Merge pull request #2403 from tylerw/tw/challenge-080
Challenge 080
Diffstat (limited to 'challenge-080')
8 files changed, 100 insertions, 39 deletions
diff --git a/challenge-080/tyler-wardhaugh/clojure/README.md b/challenge-080/tyler-wardhaugh/clojure/README.md index 37d274beb5..57a8bbe6c2 100644 --- a/challenge-080/tyler-wardhaugh/clojure/README.md +++ b/challenge-080/tyler-wardhaugh/clojure/README.md @@ -1,13 +1,13 @@ -# tw.weekly.c79 +# tw.weekly.c80 -The Weekly Challenge - #079 - Tyler Wardhaugh +The Weekly Challenge - #080 - Tyler Wardhaugh ## Usage Run the project directly (shows default output from both tasks): - $ clojure -m tw.weekly.c79.core + $ clojure -m tw.weekly.c80.core Run the project's tests (which are samples from the task descriptions): @@ -15,22 +15,11 @@ Run the project's tests (which are samples from the task descriptions): Run Task #1 with input - $ clojure -m tw.weekly.c79.t1 N + $ clojure -m tw.weekly.c80.t1 A1 A2 A3 [...] Run Task #2 with input: - $ clojure -m tw.weekly.c79.t2 A1 A2 A3 [...] - -See SVG files in the `resources` directory for the histograms drawn for each of the tests for Task 2: - - - - - - - - - + $ clojure -m tw.weekly.c80.t2 A1 A2 A3 [...] ## Project Template diff --git a/challenge-080/tyler-wardhaugh/clojure/deps.edn b/challenge-080/tyler-wardhaugh/clojure/deps.edn index 988d683304..35e57a9092 100644 --- a/challenge-080/tyler-wardhaugh/clojure/deps.edn +++ b/challenge-080/tyler-wardhaugh/clojure/deps.edn @@ -1,6 +1,5 @@ {:paths ["src" "resources"] - :deps {org.clojure/clojure {:mvn/version "1.10.1"} - metasoarous/oz {:mvn/version "1.6.0-alpha26"}} + :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"}}} @@ -11,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.c79.jar" - "-C" "-m" "tw.weekly.c79"]}}} + :main-opts ["-m" "hf.depstar.uberjar" "tw.weekly.c80.jar" + "-C" "-m" "tw.weekly.c80"]}}} diff --git a/challenge-080/tyler-wardhaugh/clojure/pom.xml b/challenge-080/tyler-wardhaugh/clojure/pom.xml index a5ef0fbd29..525b004ca8 100644 --- a/challenge-080/tyler-wardhaugh/clojure/pom.xml +++ b/challenge-080/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.c79</artifactId> + <artifactId>tw.weekly.c80</artifactId> <version>0.1.0-SNAPSHOT</version> - <name>tw.weekly.c79</name> - <description>FIXME: my new application.</description> - <url>https://github.com/tw.weekly/tw.weekly.c79</url> + <name>tw.weekly.c80</name> + <description>Challenge #080</description> + <url>https://github.com/tw.weekly/tw.weekly.c80</url> <licenses> <license> <name>Eclipse Public License</name> @@ -19,9 +19,9 @@ </developer> </developers> <scm> - <url>https://github.com/tw.weekly/tw.weekly.c79</url> - <connection>scm:git:git://github.com/tw.weekly/tw.weekly.c79.git</connection> - <developerConnection>scm:git:ssh://git@github.com/tw.weekly/tw.weekly.c79.git</developerConnection> + <url>https://github.com/tw.weekly/tw.weekly.c80</url> + <connection>scm:git:git://github.com/tw.weekly/tw.weekly.c80.git</connection> + <developerConnection>scm:git:ssh://git@github.com/tw.weekly/tw.weekly.c80.git</developerConnection> <tag>HEAD</tag> </scm> <dependencies> @@ -30,11 +30,6 @@ <artifactId>clojure</artifactId> <version>1.10.1</version> </dependency> - <dependency> - <groupId>metasoarous</groupId> - <artifactId>oz</artifactId> - <version>1.6.0-alpha26</version> - </dependency> </dependencies> <build> <sourceDirectory>src</sourceDirectory> @@ -44,10 +39,6 @@ <id>clojars</id> <url>https://repo.clojars.org/</url> </repository> - <repository> - <id>sonatype</id> - <url>https://oss.sonatype.org/content/repositories/snapshots/</url> - </repository> </repositories> <distributionManagement> <repository> diff --git a/challenge-080/tyler-wardhaugh/clojure/src/tw/weekly/c80/core.clj b/challenge-080/tyler-wardhaugh/clojure/src/tw/weekly/c80/core.clj new file mode 100644 index 0000000000..d43bc8641e --- /dev/null +++ b/challenge-080/tyler-wardhaugh/clojure/src/tw/weekly/c80/core.clj @@ -0,0 +1,12 @@ +(ns tw.weekly.c80.core + (:require [tw.weekly.c80.t1 :as t1]) + (:require [tw.weekly.c80.t2 :as t2]) + (:gen-class)) + +(defn -main + "Run all tasks" + [& _] + (println "Task #1") + (t1/-main) + (println "\n\nTask #2") + (t2/-main)) diff --git a/challenge-080/tyler-wardhaugh/clojure/src/tw/weekly/c80/t1.clj b/challenge-080/tyler-wardhaugh/clojure/src/tw/weekly/c80/t1.clj new file mode 100644 index 0000000000..8540ad4d0a --- /dev/null +++ b/challenge-080/tyler-wardhaugh/clojure/src/tw/weekly/c80/t1.clj @@ -0,0 +1,27 @@ +(ns tw.weekly.c80.t1 + (:require [clojure.edn :as edn]) + (:require [clojure.set :as set])) + +;;; Task description for TASK #1 › Smallest Positive Number Bits +;Submitted by: Mohammad S Anwar +;You are given unsorted list of integers @N. +; +;Write a script to find out the smallest positive number missing. +;;;; + +(defn smallest-missing + "Determine the smallest positive integer missing in a sequence." + [coll] + (when-let [missing (->> coll + ((juxt #(set (range 1 (inc (apply max %)))) set)) + (apply set/difference) + seq)] + (apply min missing))) + +(defn -main + "Run Task 1 with a list of integers N, defaulting to the first one given in the examples." + [& args] + (let [N (or (some->> args (map edn/read-string)) [5 2 -2 0]) ] + (if-let [smallest (smallest-missing N)] + (println smallest) + (println "No positive integer is missing in the given sequence.")))) diff --git a/challenge-080/tyler-wardhaugh/clojure/src/tw/weekly/c80/t2.clj b/challenge-080/tyler-wardhaugh/clojure/src/tw/weekly/c80/t2.clj new file mode 100644 index 0000000000..8d12ce4e14 --- /dev/null +++ b/challenge-080/tyler-wardhaugh/clojure/src/tw/weekly/c80/t2.clj @@ -0,0 +1,27 @@ +(ns tw.weekly.c80.t2 + (:require [clojure.edn :as edn])) + +;;; Task description for TASK #2 › Count Candies +; Submitted by: Mohammad S Anwar +; You are given rankings of @N candidates. +; +; Write a script to find out the total candies needed for all candidates. You are asked to follow the rules below: +; +; a) You must given at least one candy to each candidate. +; b) Candidate with higher ranking get more candies than their mmediate neighbors on either side. +;;; + +(defn count-candies + "Determine the number of candies needed according to the rules in the task description." + [coll] + (let [xf (comp (map (juxt (fn [[a b _]] (if (> b a) 1 0)) + (fn [[_ b c]] (if (> b c) 1 0)))) + (map (partial apply + 1))) + source (partition 3 1 (repeat ##Inf) (concat [##Inf] coll))] + (transduce xf + source))) + +(defn -main + "Run Task 2 with a list of integers N, defaulting to the first one given in the examples." + [& args] + (let [N (or (some->> args (map edn/read-string)) [1 2 2])] + (println (count-candies N)))) diff --git a/challenge-080/tyler-wardhaugh/clojure/test/tw/weekly/c80_test.clj b/challenge-080/tyler-wardhaugh/clojure/test/tw/weekly/c80_test.clj new file mode 100644 index 0000000000..f940c2dc50 --- /dev/null +++ b/challenge-080/tyler-wardhaugh/clojure/test/tw/weekly/c80_test.clj @@ -0,0 +1,16 @@ +(ns tw.weekly.c80-test + (:require [clojure.test :refer [deftest is testing]] + [tw.weekly.c80.t1 :refer [smallest-missing]] + [tw.weekly.c80.t2 :refer [count-candies]])) + +(deftest task-1 + (testing "Task 1, Smallest Positive Number Bits" + (is (= (smallest-missing [5 2 -2 0]) 1)) + (is (= (smallest-missing [1 8 -1]) 2)) + (is (= (smallest-missing [2 0 -1]) 1)) + (is (nil? (smallest-missing [1 2 3]))))) + +(deftest task-2 + (testing "Task 2, Count Candies" + (is (= (count-candies [1, 2, 2]) 4)) + (is (= (count-candies [1, 4, 3, 2]) 7)))) diff --git a/challenge-080/tyler-wardhaugh/lua/README.md b/challenge-080/tyler-wardhaugh/lua/README.md index 91e2f8575d..db3ed46069 100644 --- a/challenge-080/tyler-wardhaugh/lua/README.md +++ b/challenge-080/tyler-wardhaugh/lua/README.md @@ -1,17 +1,17 @@ # The Weekly Challenge -The Weekly Challenge - #078 - Tyler Wardhaugh +The Weekly Challenge - #080 - Tyler Wardhaugh ## Usage Run Task 1: - $ lua -e 'require"ch-1".run({9, 10, 7, 5, 6, 1})' + $ Run Task 2: - $ lua -e 'require"ch-2".run({10, 20, 30, 40, 50}, {3, 4})' + $ Run the project's tests (which are samples from the task descriptions): |
