How to resolve the algorithm Fibonacci sequence step by step in the XLISP programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Fibonacci sequence step by step in the XLISP programming language
Table of Contents
Problem Statement
The Fibonacci sequence is a sequence Fn of natural numbers defined recursively:
Write a function to generate the nth Fibonacci number. Solutions can be iterative or recursive (though recursive solutions are generally considered too slow and are mostly used as an exercise in recursion). The sequence is sometimes extended into negative numbers by using a straightforward inverse of the positive definition: support for negative n in the solution is optional.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Fibonacci sequence step by step in the XLISP programming language
Source code in the xlisp programming language
(DEFUN FIBONACCI (N)
(FLOOR (+ (/ (EXPT (/ (+ (SQRT 5) 1) 2) N) (SQRT 5)) 0.5)))
(DEFUN RANGE (X Y)
(IF (<= X Y)
(CONS X (RANGE (+ X 1) Y))))
(PRINT (MAPCAR FIBONACCI (RANGE 1 50)))
(defun fibonacci (x)
(defun fib (a b n)
(if (= n 2)
b
(fib b (+ a b) (- n 1)) ) )
(if (< x 2)
x
(fib 1 1 x) ) )
You may also check:How to resolve the algorithm 15 puzzle solver step by step in the Racket programming language
You may also check:How to resolve the algorithm Arithmetic evaluation step by step in the Oz programming language
You may also check:How to resolve the algorithm Universal Turing machine step by step in the VBA programming language
You may also check:How to resolve the algorithm Primality by Wilson's theorem step by step in the Swift programming language
You may also check:How to resolve the algorithm Spinning rod animation/Text step by step in the Delphi programming language