Ratio limits of fibonacci-like series
Definition
$F_{n}\left(0\right)=0$
$F_{n}\left(1\right)=1$
$F_{n}\left(x\right)=n\cdot F_{n}\left(x-1\right)+F_{n}\left(x-2\right)$
For example:
$F_{1}=\left[0,1,1,2,3,5,8,13,21,34,55,89...\right]$
$F_{2}=\left[0,1,2,5,12,29,70,169,408,985...\right]$
$F_{3}=\left[0,1,3,10,33,109,360,1189,3927...\right]$
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 …
9d 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
$$\frac{n+\sqrt{n^2+4}}{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 $R_n$ as the ratio between any two terms in the $n$-fibonacci sequence defined above (where $n\in\mathbb Z$), then$$R_{-n}=R_n-n$$or equivalently,$$R_n=R_{-n}+n$$although it seems like it would have cost me an additional 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 $G(x)=F_n(x)$ for arbitrary $n\in\mathbb Z$. Now, we can write $G(x)$ in recurrence relation form as$$\lambda^2-n\lambda-1=0$$The solution to this equation (let'_s call this $\lambda_+$),$$\lambda_+=\dfrac{n+\sqrt{n^2+4}}2$$gives the ratio of one term to the next as $x\to\infty$, because $G$ does not depend on parameter $n$.
Now, if we let $G(x)=F_{-n}(x)$, the recurrence relation now becomes$$\lambda^2+n\lambda-1=0$$and now our ratio between terms is$$\lambda_-=\dfrac{-n+\sqrt{n^2+4}}2$$Finally, we get $\lambda_+-\lambda_-=n$, or equivalently$$\lambda_+=\lambda_-+n$$$$\lambda_-=\lambda_+-n$$
0 comment threads