Fibonacci sequence: Difference between revisions
Content added Content deleted
imported>Polarit (Output the last number of the range and the list of all numbers of the range) |
|||
Line 5,720: | Line 5,720: | ||
else |
else |
||
fibonacci(n - 2) + fibonacci(n - 1)</syntaxhighlight> |
fibonacci(n - 2) + fibonacci(n - 1)</syntaxhighlight> |
||
==={{header|Version 2}}=== |
|||
<syntaxhighlight lang=”elm">fib : Int -> number |
|||
fib : Int -> number |
|||
fib n = |
|||
case n of |
|||
0 -> 0 |
|||
1 -> 1 |
|||
_ -> fib (n-1) + fib (n-2) |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
elm repl |
|||
> fib 40 |
|||
102334155 : number |
|||
> List.map (\elem -> fib elem) (List.range 1 40) |
|||
[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,1346269,2178309,3524578,5702887, |
|||
9227465,14930352,24157817,39088169,63245986,102334155] |
|||
: List number |
|||
</pre> |
|||
=={{header|Emacs Lisp}}== |
=={{header|Emacs Lisp}}== |