Ratio limits of fibonacci-like series
Definition
For example:
Challenge
Given n, find the limit of the ratio between consecutive terms, correct to at least the first 5 decimal places.
Test Cases
1 -> 1.61803...
2 -> 2.41421...
3 -> 3.30277...
4 -> 4.23606...
Scoring
This is code-golf. Shortest answer in each language wins.
[APL (Dyalog Classic)], 7 byte …
4y ago
[JavaScript (Node.js)], 27 22 …
4y ago
Stax, 5 bytes òP^↓Φ Run …
4y ago
Python 3, 26 bytes ```pytho …
15d ago
4 answers
You are accessing this answer with a direct link, so it's being shown above all other answers regardless of its score. You can return to the normal view.
APL (Dyalog Classic), 7 bytes
⎕+∘÷⍣=1
Well, rak is probably not going to answer this, so I might as well ;p
0 comment threads
JavaScript (Node.js), 27 22 bytes
-5 bytes thanks to Hakerh400
Direct computation
f=n=>(n+(n*n+4)**.5)/2
Python 3, 26 bytes
lambda n:(n+(n*n+4)**.5)/2
We can actually just compute this directly, although I could have taken an alternate path considering the fact that, given 21 19 bytes:
f=lambda n:n+f(-n)if n<0else(n+(n*n+4)**.5)/2
-2 bytes by rearranging the terms
Explanation of the above statement:
We can write
for arbitrary . Now, we can write in recurrence relation form as The solution to this equation (let'_s call this ), gives the ratio of one term to the next as , because does not depend on parameter . Now, if we let
, the recurrence relation now becomes and now our ratio between terms is Finally, we get , or equivalently
0 comment threads