2018-09-30 23:01:58 +01:00
---
id: 5900f3a51000cf542c50feb8
title: 'Problem 57: Square root convergents'
2020-11-27 19:02:05 +01:00
challengeType: 5
2019-08-05 09:17:33 -07:00
forumTopicId: 302168
2018-09-30 23:01:58 +01:00
---
2020-11-27 19:02:05 +01:00
# --description--
2020-02-28 21:39:47 +09:00
2018-09-30 23:01:58 +01:00
It is possible to show that the square root of two can be expressed as an infinite continued fraction.
2020-02-28 21:39:47 +09:00
< div style = 'text-align: center;' > $\sqrt 2 =1+ \frac 1 {2+ \frac 1 {2 +\frac 1 {2+ \dots}}}$</ div >
2018-09-30 23:01:58 +01:00
By expanding this for the first four iterations, we get:
2020-02-28 21:39:47 +09:00
2020-11-27 19:02:05 +01:00
$1 + \\frac 1 2 = \\frac 32 = 1.5$
2020-02-28 21:39:47 +09:00
2020-11-27 19:02:05 +01:00
$1 + \\frac 1 {2 + \\frac 1 2} = \\frac 7 5 = 1.4$
2020-02-28 21:39:47 +09:00
2020-11-27 19:02:05 +01:00
$1 + \\frac 1 {2 + \\frac 1 {2+\\frac 1 2}} = \\frac {17}{12} = 1.41666 \\dots$
2020-02-28 21:39:47 +09:00
2020-11-27 19:02:05 +01:00
$1 + \\frac 1 {2 + \\frac 1 {2+\\frac 1 {2+\\frac 1 2}}} = \\frac {41}{29} = 1.41379 \\dots$
2020-02-28 21:39:47 +09:00
2020-11-27 19:02:05 +01:00
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.
2020-02-28 21:39:47 +09:00
2018-09-30 23:01:58 +01:00
In the first one-thousand expansions, how many fractions contain a numerator with more digits than denominator?
2020-02-28 21:39:47 +09:00
2020-11-27 19:02:05 +01:00
# --hints--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
`squareRootConvergents()` should return a number.
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```js
assert(typeof squareRootConvergents() === 'number');
```
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
`squareRootConvergents()` should return 153.
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```js
assert.strictEqual(squareRootConvergents(), 153);
2018-09-30 23:01:58 +01:00
```
2020-11-27 19:02:05 +01:00
# --seed--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
## --seed-contents--
2018-09-30 23:01:58 +01:00
```js
2020-02-28 21:39:47 +09:00
function squareRootConvergents() {
2020-09-15 09:57:40 -07:00
2018-09-30 23:01:58 +01:00
return true;
}
2020-02-28 21:39:47 +09:00
squareRootConvergents();
2018-09-30 23:01:58 +01:00
```
2020-11-27 19:02:05 +01:00
# --solutions--
2018-09-30 23:01:58 +01:00
```js
// solution required
```