How to resolve the algorithm Cullen and Woodall numbers step by step in the Lua programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Cullen and Woodall numbers step by step in the Lua programming language

Table of Contents

Problem Statement

A Cullen number is a number of the form n × 2n + 1 where n is a natural number. A Woodall number is very similar. It is a number of the form n × 2n - 1 where n is a natural number. So for each n the associated Cullen number and Woodall number differ by 2. Woodall numbers are sometimes referred to as Riesel numbers or Cullen numbers of the second kind.

Cullen primes are Cullen numbers that are prime. Similarly, Woodall primes are Woodall numbers that are prime. It is common to list the Cullen and Woodall primes by the value of n rather than the full evaluated expression. They tend to get very large very quickly. For example, the third Cullen prime, n == 4713, has 1423 digits when evaluated.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Cullen and Woodall numbers step by step in the Lua programming language

Source code in the lua programming language

function T(t) return setmetatable(t, {__index=table}) end
table.range = function(t,n) local s=T{} for i=1,n do s[i]=i end return s end
table.map = function(t,f) local s=T{} for i=1,#t do s[i]=f(t[i]) end return s end

function cullen(n) return (n<<n)+1 end
print("First 20 Cullen numbers:")
print(T{}:range(20):map(cullen):concat(" "))

function woodall(n) return (n<<n)-1 end
print("First 20 Woodall numbers:")
print(T{}:range(20):map(woodall):concat(" "))


  

You may also check:How to resolve the algorithm Sieve of Pritchard step by step in the J programming language
You may also check:How to resolve the algorithm Deconvolution/1D step by step in the 11l programming language
You may also check:How to resolve the algorithm Find limit of recursion step by step in the Oz programming language
You may also check:How to resolve the algorithm Bitmap/Bézier curves/Cubic step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Return multiple values step by step in the VBA programming language