2018-09-30 22:01:58 +00:00
---
id: 5900f3c81000cf542c50fedb
title: 'Problem 92: Square digit chains'
2020-11-27 18:02:05 +00:00
challengeType: 5
2019-08-05 16:17:33 +00:00
forumTopicId: 302209
2021-01-13 02:31:00 +00:00
dashedName: problem-92-square-digit-chains
2018-09-30 22:01:58 +00:00
---
2020-11-27 18:02:05 +00:00
# --description--
2020-02-28 12:39:47 +00:00
2018-09-30 22:01:58 +00:00
A number chain is created by continuously adding the square of the digits in a number to form a new number until it has been seen before.
2020-02-28 12:39:47 +00:00
2018-09-30 22:01:58 +00:00
For example,
2020-02-28 12:39:47 +00:00
< div style = 'margin-left: 4em;' >
44 → 32 → 13 → 10 → < strong > 1< / strong > → < strong > 1< / strong > < br >
85 → < strong > 89< / strong > → 145 → 42 → 20 → 4 → 16 → 37 → 58 → < strong > 89< / strong >
< / div >
2018-09-30 22:01:58 +00:00
Therefore any chain that arrives at 1 or 89 will become stuck in an endless loop. What is most amazing is that EVERY starting number will eventually arrive at 1 or 89.
2020-02-28 12:39:47 +00:00
2018-09-30 22:01:58 +00:00
How many starting numbers below ten million will arrive at 89?
2020-02-28 12:39:47 +00:00
2020-11-27 18:02:05 +00:00
# --hints--
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
`squareDigitChains()` should return a number.
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
```js
assert(typeof squareDigitChains() === 'number');
```
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
`squareDigitChains()` should return 8581146.
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
```js
assert.strictEqual(squareDigitChains(), 8581146);
2018-09-30 22:01:58 +00:00
```
2020-11-27 18:02:05 +00:00
# --seed--
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
## --seed-contents--
2018-09-30 22:01:58 +00:00
```js
2020-02-28 12:39:47 +00:00
function squareDigitChains() {
2020-09-15 16:57:40 +00:00
2018-09-30 22:01:58 +00:00
return true;
}
2020-02-28 12:39:47 +00:00
squareDigitChains();
2018-09-30 22:01:58 +00:00
```
2020-11-27 18:02:05 +00:00
# --solutions--
2018-09-30 22:01:58 +00:00
```js
// solution required
```