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

Published on 12 May 2024 09:40 PM
#Jq

How to resolve the algorithm Fibonacci n-step number sequences step by step in the jq 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 jq programming language

Source code in the jq programming language

# Input: the initial array
def nacci(arity; len):
  arity as $arity | len as $len
  | reduce range(length; $len) as $i
      (.;
       ([0, (length - $arity)] | max ) as $lower
       | . + [ .[ ($lower) : length] | add] ) ;

def fib(arity; len):
  arity as $arity | len as $len
  | [1,1] | nacci($arity; $arity) | nacci($arity; $len) ;
 
def lucas(arity; len):
  arity as $arity | len as $len
  | [2,1] | nacci($arity; $arity) | nacci($arity; $len) ;

def main:
    (range(2; 11) | "fib(\(.)): \(fib(.; 15))"),
    (range(2; 11) | "lucas(\(.)): \(lucas(.; 15))")
;

main

  

You may also check:How to resolve the algorithm Call a foreign-language function step by step in the Mercury programming language
You may also check:How to resolve the algorithm Map range step by step in the Lambdatalk programming language
You may also check:How to resolve the algorithm 100 doors step by step in the Python programming language
You may also check:How to resolve the algorithm Middle three digits step by step in the Oforth programming language
You may also check:How to resolve the algorithm Luhn test of credit card numbers step by step in the Bash programming language