How to resolve the algorithm Hickerson series of almost integers step by step in the Wren programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Hickerson series of almost integers step by step in the Wren programming language

Table of Contents

Problem Statement

The following function,   due to D. Hickerson,   is said to generate "Almost integers" by the "Almost Integer" page of Wolfram MathWorld,   (December 31 2013).   (See formula numbered   51.)

The function is:

h ( n )

n !

2 ( ln ⁡

2

)

n + 1

{\displaystyle h(n)={\operatorname {n} ! \over 2(\ln {2})^{n+1}}}

It is said to produce "almost integers" for   n   between   1   and   17.
The purpose of the task is to verify this assertion. Assume that an "almost integer" has either a nine or a zero as its first digit after the decimal point of its decimal string representation

Calculate all values of the function checking and stating which are "almost integers". Note: Use extended/arbitrary precision numbers in your calculation if necessary to ensure you have adequate precision of results as for example:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Hickerson series of almost integers step by step in the Wren programming language

Source code in the wren programming language

import "./fmt" for Fmt
import "./big" for BigInt, BigDec

var hickerson = Fn.new { |n|
    var fact = BigDec.fromBigInt(BigInt.factorial(n), 64)
    var ln2 = BigDec.ln2 // precise to 64 decimal digits
    return fact / (BigDec.two * ln2.pow(n+1))
}

System.print("Values of h(n), truncated to 1 dp, and whether 'almost integers' or not:")
for (i in 1..17) {
    // truncate to 1 d.p and show final zero if any
    var h = hickerson.call(i).toString(1, false, true)
    var k = h.count - 1
    var ai = (h[k] == "0" || h[k] == "9")
    Fmt.print("$2d: $20s $s", i, h, ai)
}


  

You may also check:How to resolve the algorithm Luhn test of credit card numbers step by step in the Ceylon programming language
You may also check:How to resolve the algorithm CSV data manipulation step by step in the Kotlin programming language
You may also check:How to resolve the algorithm SHA-256 step by step in the Python programming language
You may also check:How to resolve the algorithm Parsing/RPN calculator algorithm step by step in the Scala programming language
You may also check:How to resolve the algorithm Memory allocation step by step in the Python programming language