2018-09-30 22:01:58 +00:00
---
id: 5900f4021000cf542c50ff13
title: 'Problem 149: Searching for a maximum-sum subsequence'
2020-11-27 18:02:05 +00:00
challengeType: 5
2019-08-05 16:17:33 +00:00
forumTopicId: 301778
2021-01-13 02:31:00 +00:00
dashedName: problem-149-searching-for-a-maximum-sum-subsequence
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
2021-07-14 11:05:12 +00:00
Looking at the table below, it is easy to verify that the maximum possible sum of adjacent numbers in any direction (horizontal, vertical, diagonal or anti-diagonal) is $16 (= 8 + 7 + 1)$.
2018-09-30 22:01:58 +00:00
2021-07-14 11:05:12 +00:00
$$\begin{array}{|r|r|r|r|}
\hline
− 2 & 5 & 3 & 2 \\\\ \hline
9 & − 6 & 5 & 1 \\\\ \hline
3 & 2 & 7 & 3 \\\\ \hline
− 1 & 8 & − 4 & 8 \\\\ \hline
\end{array}$$
2018-09-30 22:01:58 +00:00
Now, let us repeat the search, but on a much larger scale:
First, generate four million pseudo-random numbers using a specific form of what is known as a "Lagged Fibonacci Generator":
2021-07-14 11:05:12 +00:00
For $1 ≤ k ≤ 55$, $s_k = (100003 − 200003k + 300007{k}^3) \\ (modulo\\ 1000000) − 500000$.
2018-09-30 22:01:58 +00:00
2021-07-14 11:05:12 +00:00
For $56 ≤ k ≤ 4000000$, $s_k = (s_{k − 24} + s_{k − 55} + 1000000) \\ (modulo\\ 1000000) − 500000$.
2018-09-30 22:01:58 +00:00
2021-07-14 11:05:12 +00:00
Thus, $s_{10} = − 393027$ and $s_{100} = 86613$.
The terms of $s$ are then arranged in a 2000× 2000 table, using the first 2000 numbers to fill the first row (sequentially), the next 2000 numbers to fill the second row, and so on.
2018-09-30 22:01:58 +00:00
Finally, find the greatest sum of (any number of) adjacent entries in any direction (horizontal, vertical, diagonal or anti-diagonal).
2020-11-27 18:02:05 +00:00
# --hints--
2018-09-30 22:01:58 +00:00
2021-07-14 11:05:12 +00:00
`maximumSubSequence()` should return `52852124` .
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
```js
2021-07-14 11:05:12 +00:00
assert.strictEqual(maximumSubSequence(), 52852124);
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-14 11:05:12 +00:00
function maximumSubSequence() {
2020-09-15 16:57:40 +00:00
2018-09-30 22:01:58 +00:00
return true;
}
2021-07-14 11:05:12 +00:00
maximumSubSequence();
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
```