How to resolve the algorithm Fibonacci n-step number sequences step by step in the Powershell programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Fibonacci n-step number sequences step by step in the Powershell programming language

Table of Contents

Problem Statement

These number series are an expansion of the ordinary Fibonacci sequence where: For small values of

n

{\displaystyle n}

, Greek numeric prefixes are sometimes used to individually name each series. Allied sequences can be generated where the initial values are changed:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Fibonacci n-step number sequences step by step in the Powershell programming language

Source code in the powershell programming language

#Create generator of extended fibonaci
Function Get-ExtendedFibonaciGenerator($InitialValues ){
    $Values = $InitialValues
    {
        #exhaust initial values first before calculating next values by summation
        if ($InitialValues.Length -gt 0) {
            $NextValue = $InitialValues[0]
            $Script:InitialValues = $InitialValues | Select -Skip 1
            return $NextValue
        }

        $NextValue = $Values | Measure-Object -Sum | Select -ExpandProperty Sum
        $Script:Values = @($Values | Select-Object -Skip 1) + @($NextValue)

        $NextValue
    }.GetNewClosure()
}


$Name = 'fibo tribo tetra penta hexa hepta octo nona deca'.Split()
0..($Name.Length-1) | foreach { $Index = $_
    $InitialValues = @(1) + @(foreach ($I In 0..$Index) { [Math]::Pow(2,$I) })
    $Generator = Get-ExtendedFibonaciGenerator $InitialValues
    [PSCustomObject] @{
        n        = $InitialValues.Length;
        Name     = "$($Name[$Index])naci";
        Sequence = 1..15 | foreach { & $Generator } | Join-String -Separator ','
    }
} | Format-Table -AutoSize


  

You may also check:How to resolve the algorithm Super-d numbers step by step in the Swift programming language
You may also check:How to resolve the algorithm Brazilian numbers step by step in the Haskell programming language
You may also check:How to resolve the algorithm Pisano period step by step in the Julia programming language
You may also check:How to resolve the algorithm Fivenum step by step in the SAS programming language
You may also check:How to resolve the algorithm Euler's identity step by step in the Go programming language