Fibonacci sequence: Difference between revisions
Content added Content deleted
(Added another Pascal solution (doubling, iterative)) |
(→J: add iterative implementation) |
||
Line 7,592: | Line 7,592: | ||
=={{header|J}}== |
=={{header|J}}== |
||
The [https://code.jsoftware.com/wiki/Essays/Fibonacci_Sequence Fibonacci Sequence essay] on the J Wiki presents a number of different ways of obtaining the nth Fibonacci number. |
The [https://code.jsoftware.com/wiki/Essays/Fibonacci_Sequence Fibonacci Sequence essay] on the J Wiki presents a number of different ways of obtaining the nth Fibonacci number. |
||
⚫ | |||
⚫ | |||
⚫ | |||
Iteration: |
|||
<syntaxhighlight lang="j">fibN=: [: {."1 +/\@|.@]^:[&0 1</syntaxhighlight> |
|||
'''Examples:''' |
'''Examples:''' |
||
<syntaxhighlight lang="j"> fibN 12 |
<syntaxhighlight lang="j"> fibN 12 |
||
Line 7,599: | Line 7,603: | ||
fibN i.31 |
fibN i.31 |
||
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040</syntaxhighlight> |
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040</syntaxhighlight> |
||
⚫ | |||
=={{header|Java}}== |
=={{header|Java}}== |