Fibonnacci Sequence 
Author Message
 Fibonnacci Sequence

John Clark writes on Monday, April 22:

Quote:
> Since I do not use Fibonacci numbers a lot I use the function below.  It may
> not be as fast as some, but it follows the tradition of "one liners"

>       {DEL} Z {ASSIGN} FIB N
>  [1] Z{ASSIGN}1{DROP}{EXECUTE}((3{TIMES}N){RESHAPE}'{ROTATE}+\'),'1 0'
>       {DEL}

The idea can be implemented neatly in J using the power operator ^:
instead of execute.  Moreover, because power accepts an array of powers,
the function can be written readily to work on array arguments.  Thus:


   f i.20
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181
   f 5*i.5
0 5 55 610 6765



Sat, 10 Oct 1998 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Fibonnacci

2. WTF is Fibonnacci

3. Calling a sequence of commands with a sequence of Tkinter buttons

4. how to interrupt a while loop with a sequence in it without polling each frame of the sequence.

5. Sobol Sequences

6. ODBC function sequence error

7. C calling sequence

8. C calling sequence

9. Comparing a sequence of numbers

10. Collating sequence of Hex ...

11. Fun instruction sequences to set CC

12. need help with splitting image sequence filenames

 

 
Powered by phpBB® Forum Software