Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,26 +1,14 @@
|
|||
# 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 =
|
||||
# (fib n) = the nth Fibonacci number
|
||||
\fib=
|
||||
(
|
||||
\fibonacci == (\x\y
|
||||
item x;
|
||||
\z = (+ x y)
|
||||
fibonacci y z
|
||||
)
|
||||
|
||||
fibonacci 1 1
|
||||
(@\loop\x\y\n
|
||||
le n 0 x;
|
||||
\z=(+ x y)
|
||||
\n=(- n 1)
|
||||
loop y z n
|
||||
)
|
||||
0 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)
|
||||
# Now test it:
|
||||
for 0 20 (\n say (fib n))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue