fix(challenges): The rest of the S problems
This commit is contained in:
@@ -6,8 +6,7 @@ challengeType: 5
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
For this task, the Stern-Brocot sequence is to be generated by an algorithm similar to that employed in generating the
|
||||
<a href="http://rosettacode.org/wiki/Fibonacci sequence">Fibonacci sequence</a>.
|
||||
For this task, the Stern-Brocot sequence is to be generated by an algorithm similar to that employed in generating the <a href="http://rosettacode.org/wiki/Fibonacci sequence" target="_blank">Fibonacci sequence</a>.
|
||||
<ol>
|
||||
<li>The first and second members of the sequence are both 1:</li>
|
||||
<ul><li>1, 1</li></ul>
|
||||
@@ -31,12 +30,11 @@ For this task, the Stern-Brocot sequence is to be generated by an algorithm simi
|
||||
<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>
|
||||
Create a function that returns the $ n^{th} $ member of the sequence using the method outlined above.
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
|
||||
Create a function that returns the $ n^{th} $ member of the sequence using the method outlined above.
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
@@ -67,7 +65,7 @@ tests:
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
function sternBrocot (num) {
|
||||
function sternBrocot(num) {
|
||||
// Good luck!
|
||||
}
|
||||
```
|
||||
@@ -79,7 +77,7 @@ function sternBrocot (num) {
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
function sternBrocot (num) {
|
||||
function sternBrocot(num) {
|
||||
function f(n) {
|
||||
return n < 2 ? n : (n & 1) ? f(Math.floor(n / 2)) + f(Math.floor(n / 2 + 1)) : f(Math.floor(n / 2));
|
||||
}
|
||||
|
Reference in New Issue
Block a user