Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NB. Generates y Fibonacci numbers starting with 0 1.
- NB. If the y argument is boxed, generates
- NB. Fibonacci numbers up to the given number.
- NB. Tribonacci numbers (and so on) can be generated
- NB. as follows: 0 0 1x fibonacci 1e3 or (<3) fibonacci 1e3.
- fibonacci =: 3 : 0 "0 1 0
- 0x 1x fibonacci y
- :
- if. L.x do.
- x=.1x,~0$~<:>x
- end.
- (,a)^:((>y)>#`(a=.+/@((-#x)&{.))@.(L.y))^:_ x
- )
- NB. Examples:
- NB. First 100 Fibonacci numbers
- fibonacci 100
- NB. Fibonacci numbers up to 100
- fibonacci <100
- NB. Two ways to do the first 10 Tribonacci numbers
- 0 0 1x fibonacci 10
- (<3) fibonacci 10
- NB. The Quadribonacci numbers up to 1e6
- (<5) fibonacci <1e6
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement