Revolucent

Even better Fibonacci in J

May 30th, 2015
829
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.
  6. fibonacci =: 3 : 0 "0 1 0
  7.   0x 1x fibonacci y
  8. :
  9.   (,a)^:((>y)>#`(a=.+/@((-#x)&{.))@.(L.y))^:_ x
  10. )
  11.  
  12. NB. Examples:
  13.  
  14. NB. Generate the first 20 Fibonacci numbers:
  15. fibonacci 20
  16.  
  17. NB. Generate the first 20 Tribonacci numbers:
  18. 0 0 1x fibonacci 20
  19.  
  20. NB. Generate the Fibonacci numbers up to 1e8:
  21. fibonacci <1e8
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.

×