About one task that is no longer offered at the interview
In one company, the following task was proposed to candidates for a programmer’s vacancy. Find fraction value:
f r a c 1 1 + f r a c 1 1 + f r a c 1 1 + f r a c 1 1 + . . .
To solve this problem, knowledge of the nature of such fractions and the area in which these fractions are applied is not required. It is only necessary to note that the proposed expression is self-similar and can be represented as:
x = f r a c 1 1 + x
And this, in turn, leads to the usual quadratic equation:
x 2 + x - 1 = 0x = f r a c s q r t ( 5 ) - 1 2x=0.618033988...
Now let's say that these fractions have a special name, these are continued fractions, and they are used as one of the forms for recording real numbers. In this example, the infinite continued fraction has the simplest representation. In her record only units are used, and the length of her period is also equal to one. It is curious that the number it expresses is very widely represented, and not only in the mathematical world, and even has its own name — the reciprocal of the “golden section”. We obtain several approximations for a given number using its representation via a continued fraction. In the first step, we discard the second term in the denominator. Will get frac11 , we now write the following approximation, using the result obtained, as the second term in the sum under the fraction sign frac11+frac11=frac12 Repeat this operation again. frac11+frac12=frac23 As a result, we get the following row:
frac11,frac12,frac23,frac35,frac58,frac813...
We now turn to such a concept as the Fibonacci sequence. So called members of the number series, compiled according to the following rule. The first and second members of the series are equal to one, and each succeeding is equal to the sum of the two previous ones.
1,1,2,3,5,8,13,21...
Compose a series formed by the relations of two adjacent members of the Fibonacci sequence
frac11,frac12,frac23,frac35,frac58,frac813...
Isn't it a familiar record? Indeed, the limit of the ratio of two Fibonacci numbers is expressed by the reciprocal of the “golden section”. We get this result. From the definition it follows that
Fi+1=Fi+Fi−1
fracFi+1Fi=1+fracFi−1Fi
We introduce the following notation
si−j=fracFiFj
Then the previous equality is written as
s1=1+s−1
In the limit
s1=frac1s−1
We introduce the notation x=s−1 . Then we get the equation that was already given at the beginning of the article.
x=frac11+x
Now consider the sequence in which the first three terms are equal to one, and each succeeding is the sum of the three previous ones.
1,1,1,3,5,9,17,31,57,105,...
Let us find the limit to which the ratio of two neighboring terms of the sequence tends. By definition
Fi+3=Fi+Fi+1+Fi+2
Divide the left and right side into Fi+1 . Then, in the notation used earlier, we can write:
s2=s−1+s1+1
Now divide the left and right side Fi+2 . We get the following relation:
s1=s−2+s−1+1
Denote
s1=xs2=y
In the new notation, the system of equations will look like this:
y=frac1x+x+1x=frac1x+frac1y+1
This system is given to the following equation:
y3−3y2−y−1=0
It has one real solution.
y=3.382976...
If we consider a series for a sequence in which each member is equal to the sum of the previous four,