Files
freeCodeCamp/curriculum/challenges/english/08-coding-interview-prep/project-euler/problem-57-square-root-convergents.english.md
Kristofer Koishigawa 6cfd0fc503 fix: improve Project Euler descriptions, challenge seeds, and test cases (#38016)
* fix: improve Project Euler descriptions and test case

Improve formatting of Project Euler test descriptions. Also add poker hands array and new test case for problem 54

* feat: add typeof tests and gave functions proper names for first 100 challenges

* fix: continue fixing test descriptions and adding "before test" sections

* fix: address review comments

* fix: adjust grids in 18 and 67 and fix some text that reference files rather than the given arrays

* fix: implement bug fixes and improvements from review

* fix: remove console.log statements from seed and solution
2020-02-28 06:39:47 -06:00

1.7 KiB

id, challengeType, title, forumTopicId
id challengeType title forumTopicId
5900f3a51000cf542c50feb8 5 Problem 57: Square root convergents 302168

Description

It is possible to show that the square root of two can be expressed as an infinite continued fraction.

$\sqrt 2 =1+ \frac 1 {2+ \frac 1 {2 +\frac 1 {2+ \dots}}}$

By expanding this for the first four iterations, we get:

1 + \frac 1 2 = \frac 32 = 1.5

1 + \frac 1 {2 + \frac 1 2} = \frac 7 5 = 1.4

1 + \frac 1 {2 + \frac 1 {2+\frac 1 2}} = \frac {17}{12} = 1.41666 \dots

1 + \frac 1 {2 + \frac 1 {2+\frac 1 {2+\frac 1 2}}} = \frac {41}{29} = 1.41379 \dots

The next three expansions are \frac {99}{70}, \frac {239}{169}, and \frac {577}{408}, but the eighth expansion, \frac {1393}{985}, is the first example where the number of digits in the numerator exceeds the number of digits in the denominator.

In the first one-thousand expansions, how many fractions contain a numerator with more digits than denominator?

Instructions

Tests

tests:
  - text: <code>squareRootConvergents()</code> should return a number.
    testString: assert(typeof squareRootConvergents() === 'number');
  - text: <code>squareRootConvergents()</code> should return 153.
    testString: assert.strictEqual(squareRootConvergents(), 153);

Challenge Seed

function squareRootConvergents() {
  // Good luck!
  return true;
}

squareRootConvergents();

Solution

// solution required