Revolucent

Finally the Greatest Fibonacci in J!

Jul 5th, 2015
772
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. NB. Generates y Fibonacci numbers starting with 0 1.
  2. NB. If the y argument is boxed, generates
  3. NB. Fibonacci numbers up to the given number.
  4. NB. Tribonacci numbers (and so on) can be generated
  5. NB. as follows: 0 0 1x fibonacci 1e3 or (<3) fibonacci 1e3.
  6. fibonacci =: 3 : 0 "0 1 0
  7.     0x 1x fibonacci y
  8. :
  9.   if. L.x do.
  10.     x=.1x,~0$~<:>x
  11.   end.
  12.   (,a)^:((>y)>#`(a=.+/@((-#x)&{.))@.(L.y))^:_ x
  13. )
  14.  
  15. NB. Examples:
  16.  
  17. NB. First 100 Fibonacci numbers
  18. fibonacci 100
  19.  
  20. NB. Fibonacci numbers up to 100
  21. fibonacci <100
  22.  
  23. NB. Two ways to do the first 10 Tribonacci numbers
  24. 0 0 1x fibonacci 10
  25. (<3) fibonacci 10
  26.  
  27. NB. The Quadribonacci numbers up to 1e6
  28. (<5) fibonacci <1e6
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×