Fibonacci calculator

Using Nyquist scripts in Audacity.
Post and download new plug-ins.

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

Fibonacci calculator

Permanent link to this post Posted by steve » Thu Mar 02, 2017 10:49 pm

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)
steve
Site Admin
 
Posts: 44458
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Return to Nyquist



Who is online

Users browsing this forum: No registered users and 3 guests