François-René Rideau ([info]fare) wrote,
@ 2004-08-19 23:21:00
Previous Entry  Add to memories!  Tell a Friend!  Next Entry
Current music:Julia Ecklar - God Wrote In Lisp
Entry tags:code, en, lisp, mathematics

Fun with Fibonacci

Everyone having studied science has met Fibonacci numbers somewhere or another in his curriculum. And everyone having studied recursion in programming languages has at one moment or another been taught how to "optimize" an exponentially slow recursive implementation of the Fibonacci function into a linearly slow iterative loop. Except they were lied to. For that loop they learnt as a model to emulate is far from "optimal". There exists an algorithm that is (asymptotically) infinitely faster. And to understand how this algorithm may be devised allows us to explore a few ways that expressive languages like Lisp can open your mind to horizons unconceivable using such inexpressive and awkward languages as are mainstream in the industry. Have a look at fibonacci.lisp




(Post a new comment)

broken link to the actual code
(Anonymous)
2006-04-06 04:55 pm UTC (link)
Your link and/or script meant to show the Lisp code seems to be broken..

(Reply to this) (Thread)

fixed link to the actual code
[info]fare
2006-04-06 11:47 pm UTC (link)
Oops. I don't use CVS anymore. I uploaded the (now stable) file to a new location and updated the link. Sorry for the trouble and thanks for your interest.

(Reply to this) (Parent)


[info]fusiongyro
2007-11-11 02:53 am UTC (link)
May I offer you another?


(defun fibs-series (n)
	     (let ((fibs (scan-fn '(values :integer :integer)
                                  (lambda () (values 1 1))
                                  (lambda (x y) (values y (+ x y))))))
               (collect-last (subseries fibs (1- n) n))))

(Reply to this)


Create an Account
Forgot your login or password?
Login w/ OpenID
English • Español • Deutsch • Русский…