Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users

Dashboard
Notifications
Mark all as read
Challenges

Ratio limits of fibonacci-like series

+1
−0

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.

Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

0 comments

3 answers

+2
−0

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}$$

Try it online!

Why does this post require moderator attention?
You might want to add some details to your flag.

4 comments

Nice, interested in how you figured out the explicit formula. rak1507‭ 3 months ago

@rak1507 lol, does "looking it up" count as an answer to that question? You can derive it pretty easily though by simply assuming that it converges to $F_n(x+1)=rF_n(x)$ (where r is the ratio we want) and plugging it into recurrence equation. Moshi‭ 3 months ago

Math.sqrt -> **.5 Hakerh400‭ 3 months ago

@Hakerh400 Thanks! Moshi‭ 3 months ago

+2
−0

APL (Dyalog Classic), 7 bytes

⎕+∘÷⍣=1

Well, rak is probably not going to answer this, so I might as well ;p

Try it online!

Why does this post require moderator attention?
You might want to add some details to your flag.

0 comments

+0
−0

Stax, 5 bytes

òP^↓Φ

Run and debug it

Same idea as Quintec's answer.

Input as a floating point number.

Explanation

1gpun+
1        start with 1
 gp      apply the following till a fixpoint:
   u     reciprocal
    n+   add the input
Why does this post require moderator attention?
You might want to add some details to your flag.

0 comments

Sign up to answer this question »

This community is part of the Codidact network. We have other communities too — take a look!

You can also join us in chat!

Want to advertise this community? Use our templates!