How to resolve the algorithm Emirp primes step by step in the Clojure programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Emirp primes step by step in the Clojure programming language

Table of Contents

Problem Statement

An   emirp   (prime spelled backwards)   are primes that when reversed   (in their decimal representation)   are a different prime. (This rules out palindromic primes.)

In each list, the numbers should be in order. Invoke the (same) program once per task requirement, this will show what limit is used as the upper bound for calculating surplus (regular) primes. The specific method of how to determine if a range or if specific values are to be shown will be left to the programmer.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Emirp primes step by step in the Clojure programming language

Source code in the clojure programming language

(defn emirp? [v]
  (let [a (biginteger v)
        b (biginteger (clojure.string/reverse (str v)))]
    (and (not= a b)
         (.isProbablePrime a 16)
         (.isProbablePrime b 16))))

; Generate the output
(println "first20:    " (clojure.string/join " " (take 20 (filter emirp? (iterate inc 0)))))
(println "7700-8000:  " (clojure.string/join " " (filter emirp? (range 7700 8000))))
(println "10,000:     " (nth (filter emirp? (iterate inc 0)) 9999))


  

You may also check:How to resolve the algorithm Ethiopian multiplication step by step in the Wren programming language
You may also check:How to resolve the algorithm Pig the dice game/Player step by step in the Racket programming language
You may also check:How to resolve the algorithm CRC-32 step by step in the Ol programming language
You may also check:How to resolve the algorithm Colorful numbers step by step in the RPL programming language
You may also check:How to resolve the algorithm Primality by trial division step by step in the Dart programming language