How to resolve the algorithm Emirp primes step by step in the F# programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Emirp primes step by step in the F# 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 F# programming language
Source code in the fsharp programming language
// Generate emirps. Nigel Galloway: November 19th., 2017
let emirp =
let rec fN n g = match n with |0->g |_->fN (n/10) (g*10+n%10)
let fG n g = n<>g && isPrime g
primes32() |> Seq.filter (fun n -> fG n (fN n 0))
emirps |> (Seq.take 20) |> Seq.iter (printf "%d ")
emirps |> Seq.skipWhile (fun n->n<7700) |> Seq.takeWhile (fun n->n<=8000) |> Seq.iter (printf "%d ")
printfn "%d" (Seq.item 9999 emirps)
// count # of emirps with n = 2 to 7 digits. Nigel Galloway: August 8th., 2018
let n=emirp |> Seq.takeWhile(fun n->n<10000000) |> Seq.countBy(fun n->match n with |n when n>999999->7
|n when n> 99999->6
|n when n> 9999->5
|n when n> 999->4
|n when n> 99->3
|_ ->2)
for n,g in n do printfn "%d -> %d" n g
You may also check:How to resolve the algorithm Loops/For step by step in the Suneido programming language
You may also check:How to resolve the algorithm Boolean values step by step in the Clean programming language
You may also check:How to resolve the algorithm Happy numbers step by step in the Fantom programming language
You may also check:How to resolve the algorithm Empty program step by step in the Suneido programming language
You may also check:How to resolve the algorithm Integer comparison step by step in the Brat programming language