2018-09-30 22:01:58 +00:00
---
id: 5900f45b1000cf542c50ff6d
title: 'Problem 238: Infinite string tour'
2020-11-27 18:02:05 +00:00
challengeType: 5
2019-08-05 16:17:33 +00:00
forumTopicId: 301883
2021-01-13 02:31:00 +00:00
dashedName: problem-238-infinite-string-tour
2018-09-30 22:01:58 +00:00
---
2020-11-27 18:02:05 +00:00
# --description--
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
Create a sequence of numbers using the "Blum Blum Shub" pseudo-random number generator:
2018-09-30 22:01:58 +00:00
2021-07-15 12:26:34 +00:00
$$
s_0 = 14025256 \\\\
s_{n + 1} = {s_n}^2 \\; mod \\; 20\\,300\\,713
$$
2018-09-30 22:01:58 +00:00
2021-07-15 12:26:34 +00:00
Concatenate these numbers $s_0s_1s_2\ldots$ to create a string $w$ of infinite length. Then, $w = 14025256741014958470038053646\ldots$
2018-09-30 22:01:58 +00:00
2021-07-15 12:26:34 +00:00
For a positive integer $k$, if no substring of $w$ exists with a sum of digits equal to $k$, $p(k)$ is defined to be zero. If at least one substring of $w$ exists with a sum of digits equal to $k$, we define $p(k) = z$, where $z$ is the starting position of the earliest such substring.
2018-09-30 22:01:58 +00:00
For instance:
2021-07-15 12:26:34 +00:00
The substrings 1, 14, 1402, … with respective sums of digits equal to 1, 5, 7, … start at position 1, hence $p(1) = p(5) = p(7) = \ldots = 1$.
2018-09-30 22:01:58 +00:00
2021-07-15 12:26:34 +00:00
The substrings 4, 402, 4025, … with respective sums of digits equal to 4, 6, 11, … start at position 2, hence $p(4) = p(6) = p(11) = \ldots = 2$.
2018-09-30 22:01:58 +00:00
2021-07-15 12:26:34 +00:00
The substrings 02, 0252, … with respective sums of digits equal to 2, 9, … start at position 3, hence $p(2) = p(9) = \ldots = 3$.
2018-09-30 22:01:58 +00:00
2021-07-15 12:26:34 +00:00
Note that substring 025 starting at position 3, has a sum of digits equal to 7, but there was an earlier substring (starting at position 1) with a sum of digits equal to 7, so $p(7) = 1$, not 3.
2018-09-30 22:01:58 +00:00
2021-07-15 12:26:34 +00:00
We can verify that, for $0 < k ≤ {10}^3$, $\sum p(k) = 4742$.
2018-09-30 22:01:58 +00:00
2021-07-15 12:26:34 +00:00
Find $\sum p(k)$, for $0 < k ≤ 2 \times {10}^{15}$.
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
# --hints--
2018-09-30 22:01:58 +00:00
2021-07-15 12:26:34 +00:00
`infiniteStringTour()` should return `9922545104535660` .
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
```js
2021-07-15 12:26:34 +00:00
assert.strictEqual(infiniteStringTour(), 9922545104535660);
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
2021-07-15 12:26:34 +00:00
function infiniteStringTour() {
2020-09-15 16:57:40 +00:00
2018-09-30 22:01:58 +00:00
return true;
}
2021-07-15 12:26:34 +00:00
infiniteStringTour();
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
```