Instruções
Sequência de Stern-Brocot
Para esta tarefa, a sequência Stern-Brocot deve ser gerada por um algoritmo semelhante ao empregado na geração da <a href="https://rosettacode.org/wiki/Fibonacci_sequence" target="_blank" rel="noopener noreferrer nofollow">Fibonacci sequence</a>.
<ol>
<li>The first and second members of the sequence are both 1:</li>
<ul><li>1, 1</li></ul>
<li>Start by considering the second member of the sequence</li>
<li>Sum the considered member of the sequence and its precedent, (1 + 1) = 2, and append it to the end of the
sequence:</li>
<ul><li>1, 1, 2</li></ul>
<li>Append the considered member of the sequence to the end of the sequence:</li>
<ul><li>1, 1, 2, 1</li></ul>
<li>Consider the next member of the series, (the third member i.e. 2)</li>
<li>GOTO 3 </li>
<ul>
<li></li>
<li> ─── Expanding another loop we get: ───</li>
<li></li>
</ul>
<li>Sum the considered member of the sequence and its precedent, (2 + 1) = 3, and append it to the end of the
sequence:</li>
<ul><li>1, 1, 2, 1, 3</li></ul>
<li>Append the considered member of the sequence to the end of the sequence:</li>
<ul><li>1, 1, 2, 1, 3, 2</li></ul>
<li>Consider the next member of the series, (the fourth member i.e. 1)</li>
</ol>
O que fazer:
Crie uma função que retorne a posição na sequência Stern-Brocot em que $ n $ é encontrado pela primeira vez, onde a sequência é gerada com o método descrito acima. Observe que essa sequência usa uma indexação baseada em 1.
Critérios de Aceitação:
Critérios de Aceitação:
Testes:
- `sternBrocot` deve ser uma função.
- `sternBrocot(2)` deve retornar um número.
- `sternBrocot(2)` deve retornar `3`.
- `sternBrocot(3)` deve retornar `5`.
- `sternBrocot(5)` deve retornar `11`.
- `sternBrocot(7)` deve retornar `19`.
- `sternBrocot(10)` deve retornar `39`.
Console