Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Question

Tweeted twitter.com/StackCodeGolf/status/1390139464186478602
Became Hot Network Question
added 15 characters in body
Source Link
user100752
user100752

You want to see how quickly the ratio of two consecutive Fibonacci numbers converges on φ.

Phi, known by the nickname "the golden ratio" and written as \$φ\$, is an irrational number, almost as popular as π and e. The exact value of \$φ\$ is \$\frac {1 + \sqrt 5} 2 = 1.618...\$

The Fibonacci sequence is a recursive series of integers calculated by

$$F_n = F_{n-1} + F_{n-2} \\ F_0 = 0 \\ F_1 = 1$$

Calculate \$φ\$'s value and the ratio \$\frac {F_n} {F_{n-1}}\$. How closely does \$φ\$ match the ratio?

Examples

\$n = 2\$, ratio: \$\frac 1 1 = 1.000\$, compared to \1ドル.618...\$, 0 decimal spots match

\$n = 5\$, ratio: \$\frac 5 3 = 1.666...\$, compared to \1ドル.618...\$, 1 decimal spot matches

Input

1 integer \$n\$ to calculate \$\frac{F_n}{F_{n-1}}\$

\$ n >= 5\$

Output

1 integer \$x\$, indicating the number of decimal places that match the value of \$φ\$

It is acceptable that the program only works accurately until the float precision limit of the language.

Test Cases

Input -> Output
5 -> 1
10 -> 2
12 -> 2
15 -> 5
20 -> 7
23 -> 7
25 -> 9
50 -> 18
100 -> 39

Tips

Do not round the ratio of \$\frac{F_n}{F_{n-1}}\$

Rounding will give you errors.

Let's look at \$n = 5\$ again.

\1ドル.666...\$ rounds to \1ドル.7\$ and \1ドル.618...\$ rounds to \1ドル.6\$, so 0 is the wrong answer.

Useful information and math.

The limit of the ratios of the consecutive Fibonacci terms as \$n\$ tends to infinity is the golden number \$φ\$. The inverse of this ratio is \$\frac 1 φ\$ which equals to \$φ−1\$.

\$\frac 1 φ = φ -1 \$

\$ \lim_{n \to \infty} \frac{F_n}{F_{n-1}} = φ\$

Winning criterion

Code Golf.

You want to see how quickly the ratio of two consecutive Fibonacci numbers converges on φ.

Phi, known by the nickname "the golden ratio" and written as \$φ\$, is an irrational number, almost as popular as π and e. The exact value of \$φ\$ is \$\frac {1 + \sqrt 5} 2 = 1.618...\$

The Fibonacci sequence is a recursive series of integers calculated by

$$F_n = F_{n-1} + F_{n-2} \\ F_0 = 0 \\ F_1 = 1$$

Calculate \$φ\$'s value and the ratio \$\frac {F_n} {F_{n-1}}\$. How closely does \$φ\$ match the ratio?

Examples

\$n = 2\$, ratio: \$\frac 1 1 = 1.000\$, compared to \1ドル.618...\$, 0 decimal spots match

\$n = 5\$, ratio: \$\frac 5 3 = 1.666...\$, compared to \1ドル.618...\$, 1 decimal spot matches

Input

1 integer \$n\$ to calculate \$\frac{F_n}{F_{n-1}}\$

Output

1 integer \$x\$, indicating the number of decimal places that match the value of \$φ\$

It is acceptable that the program only works accurately until the float precision limit of the language.

Test Cases

Input -> Output
5 -> 1
10 -> 2
12 -> 2
15 -> 5
20 -> 7
23 -> 7
25 -> 9
50 -> 18
100 -> 39

Tips

Do not round the ratio of \$\frac{F_n}{F_{n-1}}\$

Rounding will give you errors.

Let's look at \$n = 5\$ again.

\1ドル.666...\$ rounds to \1ドル.7\$ and \1ドル.618...\$ rounds to \1ドル.6\$, so 0 is the wrong answer.

Useful information and math.

The limit of the ratios of the consecutive Fibonacci terms as \$n\$ tends to infinity is the golden number \$φ\$. The inverse of this ratio is \$\frac 1 φ\$ which equals to \$φ−1\$.

\$\frac 1 φ = φ -1 \$

\$ \lim_{n \to \infty} \frac{F_n}{F_{n-1}} = φ\$

Winning criterion

Code Golf.

You want to see how quickly the ratio of two consecutive Fibonacci numbers converges on φ.

Phi, known by the nickname "the golden ratio" and written as \$φ\$, is an irrational number, almost as popular as π and e. The exact value of \$φ\$ is \$\frac {1 + \sqrt 5} 2 = 1.618...\$

The Fibonacci sequence is a recursive series of integers calculated by

$$F_n = F_{n-1} + F_{n-2} \\ F_0 = 0 \\ F_1 = 1$$

Calculate \$φ\$'s value and the ratio \$\frac {F_n} {F_{n-1}}\$. How closely does \$φ\$ match the ratio?

Examples

\$n = 2\$, ratio: \$\frac 1 1 = 1.000\$, compared to \1ドル.618...\$, 0 decimal spots match

\$n = 5\$, ratio: \$\frac 5 3 = 1.666...\$, compared to \1ドル.618...\$, 1 decimal spot matches

Input

1 integer \$n\$ to calculate \$\frac{F_n}{F_{n-1}}\$

\$ n >= 5\$

Output

1 integer \$x\$, indicating the number of decimal places that match the value of \$φ\$

It is acceptable that the program only works accurately until the float precision limit of the language.

Test Cases

Input -> Output
5 -> 1
10 -> 2
12 -> 2
15 -> 5
20 -> 7
23 -> 7
25 -> 9
50 -> 18
100 -> 39

Tips

Do not round the ratio of \$\frac{F_n}{F_{n-1}}\$

Rounding will give you errors.

Let's look at \$n = 5\$ again.

\1ドル.666...\$ rounds to \1ドル.7\$ and \1ドル.618...\$ rounds to \1ドル.6\$, so 0 is the wrong answer.

Useful information and math.

The limit of the ratios of the consecutive Fibonacci terms as \$n\$ tends to infinity is the golden number \$φ\$. The inverse of this ratio is \$\frac 1 φ\$ which equals to \$φ−1\$.

\$\frac 1 φ = φ -1 \$

\$ \lim_{n \to \infty} \frac{F_n}{F_{n-1}} = φ\$

Winning criterion

Code Golf.

added 113 characters in body
Source Link
user100752
user100752

You want to see how quickly the ratio of two consecutive Fibonacci numbers converges on φ.

Phi, known by the nickname "the golden ratio" and written as \$φ\$, is an irrational number, almost as popular as π and e. The exact value of \$φ\$ is \$\frac {1 + \sqrt 5} 2 = 1.618...\$

The Fibonacci sequence is a recursive series of integers calculated by

$$F_n = F_{n-1} + F_{n-2} \\ F_0 = 0 \\ F_1 = 1$$

Calculate \$φ\$'s value and the ratio \$\frac {F_n} {F_{n-1}}\$. How closely does \$φ\$ match the ratio?

Examples

\$n = 2\$, ratio: \$\frac 1 1 = 1.000\$, compared to \1ドル.618...\$, 0 decimal spots match

\$n = 5\$, ratio: \$\frac 5 3 = 1.666...\$, compared to \1ドル.618...\$, 1 decimal spot matches

Input

1 integer \$n\$ to calculate \$\frac{F_n}{F_{n-1}}\$

Output

1 integer \$x\$, indicating the number of decimal places that match the value of \$φ\$

It is acceptable that the program only works accurately until the float precision limit of the language.

Test Cases

Input -> Output
5 -> 1
10 -> 2
12 -> 2
15 -> 5
20 -> 7
23 -> 7
25 -> 9
50 -> 18
100 -> 3039

Tips

Do not round the ratio of \$\frac{F_n}{F_{n-1}}\$

Rounding will give you errors.

Let's look at \$n = 5\$ again.

\1ドル.666...\$ rounds to \1ドル.7\$ and \1ドル.618...\$ rounds to \1ドル.6\$, so 0 is the wrong answer.

Useful information and math.

The limit of the ratios of the consecutive Fibonacci terms as \$n\$ tends to infinity is the golden number \$φ\$. The inverse of this ratio is \$\frac 1 φ\$ which equals to \$φ−1\$.

\$\frac 1 φ = φ -1 \$

\$ \lim_{n \to \infty} \frac{F_n}{F_{n-1}} = φ\$

Winning criterion

Code Golf.

You want to see how quickly the ratio of two consecutive Fibonacci numbers converges on φ.

Phi, known by the nickname "the golden ratio" and written as \$φ\$, is an irrational number, almost as popular as π and e. The exact value of \$φ\$ is \$\frac {1 + \sqrt 5} 2 = 1.618...\$

The Fibonacci sequence is a recursive series of integers calculated by

$$F_n = F_{n-1} + F_{n-2} \\ F_0 = 0 \\ F_1 = 1$$

Calculate \$φ\$'s value and the ratio \$\frac {F_n} {F_{n-1}}\$. How closely does \$φ\$ match the ratio?

Examples

\$n = 2\$, ratio: \$\frac 1 1 = 1.000\$, compared to \1ドル.618...\$, 0 decimal spots match

\$n = 5\$, ratio: \$\frac 5 3 = 1.666...\$, compared to \1ドル.618...\$, 1 decimal spot matches

Input

1 integer \$n\$ to calculate \$\frac{F_n}{F_{n-1}}\$

Output

1 integer \$x\$, indicating the number of decimal places that match the value of \$φ\$

It is acceptable that the program only works accurately until the float precision limit of the language.

Test Cases

Input -> Output
5 -> 1
10 -> 2
12 -> 2
15 -> 5
20 -> 7
23 -> 7
25 -> 9
50 -> 18
100 -> 30

Tips

Do not round the ratio of \$\frac{F_n}{F_{n-1}}\$

Rounding will give you errors.

Let's look at \$n = 5\$ again.

\1ドル.666...\$ rounds to \1ドル.7\$ and \1ドル.618...\$ rounds to \1ドル.6\$, so 0 is the wrong answer.

Useful information and math.

The limit of the ratios of the consecutive Fibonacci terms as \$n\$ tends to infinity is the golden number \$φ\$. The inverse of this ratio is \$\frac 1 φ\$ which equals to \$φ−1\$.

\$\frac 1 φ = φ -1 \$

\$ \lim_{n \to \infty} \frac{F_n}{F_{n-1}} = φ\$

Winning criterion

Code Golf.

You want to see how quickly the ratio of two consecutive Fibonacci numbers converges on φ.

Phi, known by the nickname "the golden ratio" and written as \$φ\$, is an irrational number, almost as popular as π and e. The exact value of \$φ\$ is \$\frac {1 + \sqrt 5} 2 = 1.618...\$

The Fibonacci sequence is a recursive series of integers calculated by

$$F_n = F_{n-1} + F_{n-2} \\ F_0 = 0 \\ F_1 = 1$$

Calculate \$φ\$'s value and the ratio \$\frac {F_n} {F_{n-1}}\$. How closely does \$φ\$ match the ratio?

Examples

\$n = 2\$, ratio: \$\frac 1 1 = 1.000\$, compared to \1ドル.618...\$, 0 decimal spots match

\$n = 5\$, ratio: \$\frac 5 3 = 1.666...\$, compared to \1ドル.618...\$, 1 decimal spot matches

Input

1 integer \$n\$ to calculate \$\frac{F_n}{F_{n-1}}\$

Output

1 integer \$x\$, indicating the number of decimal places that match the value of \$φ\$

It is acceptable that the program only works accurately until the float precision limit of the language.

Test Cases

Input -> Output
5 -> 1
10 -> 2
12 -> 2
15 -> 5
20 -> 7
23 -> 7
25 -> 9
50 -> 18
100 -> 39

Tips

Do not round the ratio of \$\frac{F_n}{F_{n-1}}\$

Rounding will give you errors.

Let's look at \$n = 5\$ again.

\1ドル.666...\$ rounds to \1ドル.7\$ and \1ドル.618...\$ rounds to \1ドル.6\$, so 0 is the wrong answer.

Useful information and math.

The limit of the ratios of the consecutive Fibonacci terms as \$n\$ tends to infinity is the golden number \$φ\$. The inverse of this ratio is \$\frac 1 φ\$ which equals to \$φ−1\$.

\$\frac 1 φ = φ -1 \$

\$ \lim_{n \to \infty} \frac{F_n}{F_{n-1}} = φ\$

Winning criterion

Code Golf.

added 113 characters in body
Source Link
user100752
user100752

You want to see how quickly the ratio of two consecutive Fibonacci numbers converges on φ.

Phi, known by the nickname "the golden ratio" and written as \$φ\$, is an irrational number, almost as popular as π and e. The exact value of \$φ\$ is \$\frac {1 + \sqrt 5} 2 = 1.618...\$

The Fibonacci sequence is a recursive series of integers calculated by

$$F_n = F_{n-1} + F_{n-2} \\ F_0 = 0 \\ F_1 = 1$$

Calculate \$φ\$'s value and the ratio \$\frac {F_n} {F_{n-1}}\$. How closely does \$φ\$ match the ratio?

Examples

\$n = 2\$, ratio: \$\frac 1 1 = 1.000\$, compared to \1ドル.618...\$, 0 decimal spots match

\$n = 5\$, ratio: \$\frac 5 3 = 1.666...\$, compared to \1ドル.618...\$, 1 decimal spot matches

Input

1 integer \$n\$ to calculate \$\frac{F_n}{F_{n-1}}\$

Output

1 integer \$x\$, indicating the number of decimal places that match the value of \$φ\$

It is acceptable that the program only works accurately until the float precision limit of the language.

Test Cases

Input -> Output
5 -> 1
10 -> 2
12 -> 2
15 -> 5
20 -> 7
23 -> 7
25 -> 9
50 -> 18
100 -> 30

Tips

Do not round the ratio of \$\frac{F_n}{F_{n-1}}\$

Rounding will give you errors.

Let's look at \$n = 5\$ again.

\1ドル.666...\$ rounds to \1ドル.7\$ and \1ドル.618...\$ rounds to \1ドル.6\$, so 0 is the wrong answer.

Useful information and math.

The limit of the ratios of the consecutive Fibonacci terms as \$n\$ tends to infinity is the golden number \$φ\$. The inverse of this ratio is \$\frac 1 φ\$ which equals to \$φ−1\$.

\$\frac 1 φ = φ -1 \$

\$ \lim_{n \to \infty} \frac{F_n}{F_{n-1}} = φ\$

Winning criterion

Code Golf.

You want to see how quickly the ratio of two consecutive Fibonacci numbers converges on φ.

Phi, known by the nickname "the golden ratio" and written as \$φ\$, is an irrational number, almost as popular as π and e. The exact value of \$φ\$ is \$\frac {1 + \sqrt 5} 2 = 1.618...\$

The Fibonacci sequence is a recursive series of integers calculated by

$$F_n = F_{n-1} + F_{n-2} \\ F_0 = 0 \\ F_1 = 1$$

Calculate \$φ\$'s value and the ratio \$\frac {F_n} {F_{n-1}}\$. How closely does \$φ\$ match the ratio?

Examples

\$n = 2\$, ratio: \$\frac 1 1 = 1.000\$, compared to \1ドル.618...\$, 0 decimal spots match

\$n = 5\$, ratio: \$\frac 5 3 = 1.666...\$, compared to \1ドル.618...\$, 1 decimal spot matches

Input

1 integer \$n\$ to calculate \$\frac{F_n}{F_{n-1}}\$

Output

1 integer \$x\$, indicating the number of decimal places that match the value of \$φ\$

It is acceptable that the program only works accurately until the float precision limit of the language.

Tips

Do not round the ratio of \$\frac{F_n}{F_{n-1}}\$

Rounding will give you errors.

Let's look at \$n = 5\$ again.

\1ドル.666...\$ rounds to \1ドル.7\$ and \1ドル.618...\$ rounds to \1ドル.6\$, so 0 is the wrong answer.

Useful information and math.

The limit of the ratios of the consecutive Fibonacci terms as \$n\$ tends to infinity is the golden number \$φ\$. The inverse of this ratio is \$\frac 1 φ\$ which equals to \$φ−1\$.

\$\frac 1 φ = φ -1 \$

\$ \lim_{n \to \infty} \frac{F_n}{F_{n-1}} = φ\$

Winning criterion

Code Golf.

You want to see how quickly the ratio of two consecutive Fibonacci numbers converges on φ.

Phi, known by the nickname "the golden ratio" and written as \$φ\$, is an irrational number, almost as popular as π and e. The exact value of \$φ\$ is \$\frac {1 + \sqrt 5} 2 = 1.618...\$

The Fibonacci sequence is a recursive series of integers calculated by

$$F_n = F_{n-1} + F_{n-2} \\ F_0 = 0 \\ F_1 = 1$$

Calculate \$φ\$'s value and the ratio \$\frac {F_n} {F_{n-1}}\$. How closely does \$φ\$ match the ratio?

Examples

\$n = 2\$, ratio: \$\frac 1 1 = 1.000\$, compared to \1ドル.618...\$, 0 decimal spots match

\$n = 5\$, ratio: \$\frac 5 3 = 1.666...\$, compared to \1ドル.618...\$, 1 decimal spot matches

Input

1 integer \$n\$ to calculate \$\frac{F_n}{F_{n-1}}\$

Output

1 integer \$x\$, indicating the number of decimal places that match the value of \$φ\$

It is acceptable that the program only works accurately until the float precision limit of the language.

Test Cases

Input -> Output
5 -> 1
10 -> 2
12 -> 2
15 -> 5
20 -> 7
23 -> 7
25 -> 9
50 -> 18
100 -> 30

Tips

Do not round the ratio of \$\frac{F_n}{F_{n-1}}\$

Rounding will give you errors.

Let's look at \$n = 5\$ again.

\1ドル.666...\$ rounds to \1ドル.7\$ and \1ドル.618...\$ rounds to \1ドル.6\$, so 0 is the wrong answer.

Useful information and math.

The limit of the ratios of the consecutive Fibonacci terms as \$n\$ tends to infinity is the golden number \$φ\$. The inverse of this ratio is \$\frac 1 φ\$ which equals to \$φ−1\$.

\$\frac 1 φ = φ -1 \$

\$ \lim_{n \to \infty} \frac{F_n}{F_{n-1}} = φ\$

Winning criterion

Code Golf.

Source Link
user100752
user100752
Loading

AltStyle によって変換されたページ (->オリジナル) /