diff options
| author | Tyler Wardhaugh <tyler.wardhaugh@gmail.com> | 2022-01-14 17:14:44 -0800 |
|---|---|---|
| committer | Tyler Wardhaugh <tyler.wardhaugh@gmail.com> | 2022-01-14 17:14:44 -0800 |
| commit | 9fc81d53499ed0bc9a27766bcf1f035535a63b6f (patch) | |
| tree | ed66f7c4a69800cf398e9b4040b6d9edca014f60 | |
| parent | 25513b91fa5ea9a6801605ef1dd795550e521b8b (diff) | |
| download | perlweeklychallenge-club-9fc81d53499ed0bc9a27766bcf1f035535a63b6f.tar.gz perlweeklychallenge-club-9fc81d53499ed0bc9a27766bcf1f035535a63b6f.tar.bz2 perlweeklychallenge-club-9fc81d53499ed0bc9a27766bcf1f035535a63b6f.zip | |
Ch147 (Clojure): Task #1
| -rw-r--r-- | challenge-147/tyler-wardhaugh/clojure/src/c147/t1.clj | 29 | ||||
| -rw-r--r-- | challenge-147/tyler-wardhaugh/clojure/test/c147/t1_test.clj | 11 |
2 files changed, 40 insertions, 0 deletions
diff --git a/challenge-147/tyler-wardhaugh/clojure/src/c147/t1.clj b/challenge-147/tyler-wardhaugh/clojure/src/c147/t1.clj new file mode 100644 index 0000000000..dd9e87c6c0 --- /dev/null +++ b/challenge-147/tyler-wardhaugh/clojure/src/c147/t1.clj @@ -0,0 +1,29 @@ +(ns c147.t1 + (:require [com.hypirion.primes :as p])) + +(def TARGET 20) + +(defn digits->n + [digits] + (parse-long (apply str digits))) + +(defn left-truncatable-prime? + [n] + (let [digits (-> n str seq)] + (when (not-any? #(= \0 %) digits) + (->> (iterate rest digits) + (drop 1) + (take-while seq) + (map digits->n) + (every? p/prime?))))) + +(defn left-truncatable-primes + [n] + (->> (p/primes) + (filter left-truncatable-prime?) + (take n))) + + +(defn -main + [& _] + (println (left-truncatable-primes TARGET))) diff --git a/challenge-147/tyler-wardhaugh/clojure/test/c147/t1_test.clj b/challenge-147/tyler-wardhaugh/clojure/test/c147/t1_test.clj new file mode 100644 index 0000000000..fc527438d0 --- /dev/null +++ b/challenge-147/tyler-wardhaugh/clojure/test/c147/t1_test.clj @@ -0,0 +1,11 @@ +(ns c147.t1-test + (:require [clojure.test :refer [deftest is testing]] + [c147.t1 :as t1])) + +; source: https://oeis.org/A024785 +(def FIRST-20-LEFT-TRUNCATABLE-PRIMES + [2, 3, 5, 7, 13, 17, 23, 37, 43, 47, 53, 67, 73, 83, 97, 113, 137, 167, 173, 197]) + +(deftest target + (testing "Target identified in task description" + (is (= FIRST-20-LEFT-TRUNCATABLE-PRIMES (t1/left-truncatable-primes t1/TARGET))))) |
