## Fibonacci calculator

Using Nyquist scripts in Audacity.
Forum rules
If you require help using Audacity, please post on the forum board relevant to your operating system:
Windows
Mac OS X
GNU/Linux and Unix-like
steve
Posts: 47303
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu
Contact:

### Fibonacci calculator

Probably not very useful for audio, but perhaps of interest for some. Here's a simple Fibonacci number calculator that can be run in the Nyquist Prompt effect.
Q. Why is the maximum value of "n" 46?
A. Because Nyquist calculates using 32-bit numbers and the 47th term of the Fibonacci series is 2971215073, which is too big for a 32-bit signed integer.

Code: Select all

``````;control n "Fibonacci (n)" int "" 0 0 46

(defun fib (n)
(case n
((0 1) n)
(t (let ((fib-2 0)
(fib-1 1))
(dotimes (i (1- n) fib)
(setf fib (+ fib-2 fib-1))
(psetq fib-2 fib-1
fib-1 fib))))))

(format nil
"The ~a~a term of the Fibonacci series is: ~a"
n
(case n (1 "st")(2 "nd")(3 "rd")(t "th"))
(fib n))
``````
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)