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

Source code in the forth programming language

: length @ ;                          \ length of an array is stored at its address
: a{ here cell allot ;
: } , here over - cell / over ! ;  
 
defer nacci

: step ( a- i n -- a- i m )
    >r 1- 2dup nacci r> + ;

: steps ( a- i n -- m ) 
    0 tuck do step loop nip nip ;

:noname ( a- i -- n ) 
    over length over >                \ if i is within the array
    if cells + @                      \ fetch i...if not,
    else over length 1- steps         \ get length of array for calling step and recurse
    then ; is nacci

: show-nacci 11 1 do dup i nacci . loop cr drop ;

." fibonacci: " a{ 1 , 1 } show-nacci
." tribonacci: " a{ 1 , 1 , 2 } show-nacci
." tetranacci: " a{ 1 , 1 , 2 , 4 } show-nacci
." lucas: " a{ 2 , 1 } show-nacci


  

You may also check:How to resolve the algorithm MAC vendor lookup step by step in the JavaScript programming language
You may also check:How to resolve the algorithm Sorting algorithms/Counting sort step by step in the BBC BASIC programming language
You may also check:How to resolve the algorithm Mertens function step by step in the Ruby programming language
You may also check:How to resolve the algorithm 100 doors step by step in the ACL2 programming language
You may also check:How to resolve the algorithm Globally replace text in several files step by step in the Scala programming language