This commit is contained in:
Ingy döt Net 2013-04-10 21:29:02 -07:00
parent 764da6cbbb
commit db842d013d
19005 changed files with 197040 additions and 7 deletions

View file

@ -0,0 +1,26 @@
# fibonacci is the infinite list of all Fibonacci numbers.
#
# Note that this program uses the symbols "1" and "+". You can specify
# the definitions of those symbols however you like, allowing you to use
# any system of arithmetic you need. For example, you can use either the
# built-in long arithmetic, or infinite precision arithmetic, by simply
# defining "1" and "+" appropriately.
\fibonacci =
(
\fibonacci == (\x\y
item x;
\z = (+ x y)
fibonacci y z
)
fibonacci 1 1
)
# OK, so that's the list of *all* Fibonacci numbers. If you want the nth number,
# you can extract it with the fib function as follows. By the way, this *does*
# have the effect of caching, so once a particular point in the sequence is
# calculated, it doesn't have to be calculated again.
# (fib n) is the nth fibonacci number, starting with n==0, or 1 if n is negative.
\fib = (\n list_at fibonacci n 1)