aboutsummaryrefslogtreecommitdiff
path: root/challenge-154
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-03-06 20:53:23 +0000
committerGitHub <noreply@github.com>2022-03-06 20:53:23 +0000
commitc2ce29df13c28caf9896d1eb90031e20617f2835 (patch)
treeda84de8bf508bd71ee46617a14a4f4c83791f46d /challenge-154
parentb45785bb469b127b9ab48e53b1efe2d435cfc193 (diff)
parent87a12a7112f31ef95eed7aa9ee09833d067b3cd9 (diff)
downloadperlweeklychallenge-club-c2ce29df13c28caf9896d1eb90031e20617f2835.tar.gz
perlweeklychallenge-club-c2ce29df13c28caf9896d1eb90031e20617f2835.tar.bz2
perlweeklychallenge-club-c2ce29df13c28caf9896d1eb90031e20617f2835.zip
Merge pull request #5741 from tylerw/tw/challenge-154
Challenge 154
Diffstat (limited to 'challenge-154')
-rw-r--r--challenge-154/tyler-wardhaugh/clojure/README.md17
-rw-r--r--challenge-154/tyler-wardhaugh/clojure/bb.edn2
-rw-r--r--challenge-154/tyler-wardhaugh/clojure/build.clj19
-rw-r--r--challenge-154/tyler-wardhaugh/clojure/deps.edn7
-rw-r--r--challenge-154/tyler-wardhaugh/clojure/src/c154/t1.clj20
-rw-r--r--challenge-154/tyler-wardhaugh/clojure/src/c154/t2.clj21
-rw-r--r--challenge-154/tyler-wardhaugh/clojure/test/c154/t1_test.clj7
-rw-r--r--challenge-154/tyler-wardhaugh/clojure/test/c154/t2_test.clj10
8 files changed, 89 insertions, 14 deletions
diff --git a/challenge-154/tyler-wardhaugh/clojure/README.md b/challenge-154/tyler-wardhaugh/clojure/README.md
index c842049b9d..0172d72218 100644
--- a/challenge-154/tyler-wardhaugh/clojure/README.md
+++ b/challenge-154/tyler-wardhaugh/clojure/README.md
@@ -1,6 +1,6 @@
-# c148
+# c154
-The Weekly Challenge — #152 — Tyler Wardhaugh
+The Weekly Challenge — #154 — Tyler Wardhaugh
## Usage
@@ -8,21 +8,18 @@ Clojure ([installation instructions](https://clojure.org/guides/getting_started#
Run Task #1:
- $ clojure -M:t1 T
+ $ clojure -M:t1
# ... or ...
- $ bb run task-1 T
-
- # Alternatively, to run it via Babashka:
- $ bb run task-1-bb T
+ $ bb run task-1
Run Task #2:
- $ clojure -M:t2 R1 R2
+ $ clojure -M:t2
# ... or ...
- $ bb run task-2 R1 R2
+ $ bb run task-2
# Alternatively, to run it via Babashka:
- $ bb run task-2-bb R1 R2
+ $ bb run task-2-bb
Run the project's tests (which are samples from the task descriptions):
diff --git a/challenge-154/tyler-wardhaugh/clojure/bb.edn b/challenge-154/tyler-wardhaugh/clojure/bb.edn
index e21cd63a1e..6d0b679197 100644
--- a/challenge-154/tyler-wardhaugh/clojure/bb.edn
+++ b/challenge-154/tyler-wardhaugh/clojure/bb.edn
@@ -72,7 +72,7 @@
:task (run-task-clj :t1 *command-line-args*)}
task-1-bb {:doc "Run Task 1 (via Babashka)"
- :task (run-task-bb :t1 *command-line-args*)}
+ :task (bb-no-go :t1 *command-line-args*)}
task-2 {:doc "Run Task 2 (via clojure)"
:task (run-task-clj :t2 *command-line-args*)}
diff --git a/challenge-154/tyler-wardhaugh/clojure/build.clj b/challenge-154/tyler-wardhaugh/clojure/build.clj
new file mode 100644
index 0000000000..2edd7fd991
--- /dev/null
+++ b/challenge-154/tyler-wardhaugh/clojure/build.clj
@@ -0,0 +1,19 @@
+(ns build
+ (:refer-clojure :exclude [test])
+ (:require [org.corfield.build :as bb]))
+
+(def lib 'net.clojars.c154/c154)
+(def version "0.1.0-SNAPSHOT")
+(def main 'c154.c154)
+
+(defn test "Run the tests." [opts]
+ (bb/run-tests opts))
+
+(def clean bb/clean)
+
+(defn ci "Run the CI pipeline of tests (and build the uberjar)." [opts]
+ (-> opts
+ (assoc :lib lib :version version :main main)
+ (bb/run-tests)
+ (bb/clean)
+ (bb/uber)))
diff --git a/challenge-154/tyler-wardhaugh/clojure/deps.edn b/challenge-154/tyler-wardhaugh/clojure/deps.edn
index 2af9fe3eba..d647404dd7 100644
--- a/challenge-154/tyler-wardhaugh/clojure/deps.edn
+++ b/challenge-154/tyler-wardhaugh/clojure/deps.edn
@@ -1,8 +1,9 @@
{: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" "c152.t1"]}
- :t2 {:main-opts ["-m" "c152.t2"]}
+ {:t1 {:main-opts ["-m" "c154.t1"]}
+ :t2 {:main-opts ["-m" "c154.t2"]}
:build {:deps {io.github.seancorfield/build-clj
{:git/tag "v0.6.3" :git/sha "9b8e09b"
;; since we're building an app uberjar, we do not
diff --git a/challenge-154/tyler-wardhaugh/clojure/src/c154/t1.clj b/challenge-154/tyler-wardhaugh/clojure/src/c154/t1.clj
new file mode 100644
index 0000000000..5a0c47e862
--- /dev/null
+++ b/challenge-154/tyler-wardhaugh/clojure/src/c154/t1.clj
@@ -0,0 +1,20 @@
+(ns c154.t1
+ (:require [clojure.pprint :refer [cl-format]]
+ [clojure.set :as set]
+ [clojure.math.combinatorics :as combo]))
+
+(def GIVEN-BASE "PERL")
+(def GIVEN-PERMS
+ ["PELR" "PREL" "PERL" "PRLE" "PLER" "PLRE" "EPRL" "EPLR" "ERPL"
+ "ERLP" "ELPR" "ELRP" "RPEL" "RPLE" "REPL" "RELP" "RLPE" "RLEP"
+ "LPER" "LPRE" "LEPR" "LRPE" "LREP"])
+
+(defn find-missing
+ [base partial-perms]
+ (let [all-perms (into #{} (map #(apply str %)) (combo/permutations base))]
+ (set/difference all-perms (set partial-perms))))
+
+(defn -main
+ "Run Task 1."
+ [& args]
+ (cl-format true "~{~a~^, ~}~%" (find-missing GIVEN-BASE GIVEN-PERMS)))
diff --git a/challenge-154/tyler-wardhaugh/clojure/src/c154/t2.clj b/challenge-154/tyler-wardhaugh/clojure/src/c154/t2.clj
new file mode 100644
index 0000000000..b1f636f5a3
--- /dev/null
+++ b/challenge-154/tyler-wardhaugh/clojure/src/c154/t2.clj
@@ -0,0 +1,21 @@
+(ns c154.t2
+ (:require [clojure.pprint :refer [cl-format]]))
+
+(defn padovans
+ []
+ (let [p (promise)]
+ @(doto p
+ (deliver (list* 1 1 1 (lazy-seq (map + @p (rest @p))))))))
+
+(defn gen-padovan-primes
+ []
+ (->> (padovans)
+ (filter #(.isProbablePrime (BigInteger/valueOf %) 1000))
+ (drop 1)))
+
+(def first-ten-distinct-padovan-primes (take 10 (gen-padovan-primes)))
+
+(defn -main
+ "Run Task 2."
+ [& args]
+ (cl-format true "~{~a~^, ~}~%" first-ten-distinct-padovan-primes))
diff --git a/challenge-154/tyler-wardhaugh/clojure/test/c154/t1_test.clj b/challenge-154/tyler-wardhaugh/clojure/test/c154/t1_test.clj
new file mode 100644
index 0000000000..686425e198
--- /dev/null
+++ b/challenge-154/tyler-wardhaugh/clojure/test/c154/t1_test.clj
@@ -0,0 +1,7 @@
+(ns c154.t1-test
+ (:require [clojure.test :refer [deftest is testing]]
+ [c154.t1 :as t1]))
+
+(deftest task-1
+ (testing "Task 1 produces the correct result"
+ (is (= #{"LERP"} (t1/find-missing t1/GIVEN-BASE t1/GIVEN-PERMS)))))
diff --git a/challenge-154/tyler-wardhaugh/clojure/test/c154/t2_test.clj b/challenge-154/tyler-wardhaugh/clojure/test/c154/t2_test.clj
new file mode 100644
index 0000000000..8a54178f95
--- /dev/null
+++ b/challenge-154/tyler-wardhaugh/clojure/test/c154/t2_test.clj
@@ -0,0 +1,10 @@
+(ns c154.t2-test
+ (:require [clojure.test :refer [deftest is testing]]
+ [c154.t2 :refer [first-ten-distinct-padovan-primes]]))
+
+; Expected Output from task description
+(def PADOVAN-PRIMES [2 3 5 7 37 151 3329 23833 13091204281 3093215881333057])
+
+(deftest task-2
+ (testing "Task 2 produces the correct result"
+ (is (= first-ten-distinct-padovan-primes PADOVAN-PRIMES))))