2018-10-10 22:03:03 +00:00
---
id: 5900f4021000cf542c50ff13
2021-02-06 04:42:36 +00:00
title: 'Problem 149: Searching for a maximum-sum subsequence'
2018-10-10 22:03:03 +00:00
challengeType: 5
2021-02-06 04:42:36 +00:00
forumTopicId: 301778
2021-01-13 02:31:00 +00:00
dashedName: problem-149-searching-for-a-maximum-sum-subsequence
2018-10-10 22:03:03 +00:00
---
2020-12-16 07:37:30 +00:00
# --description--
2020-02-17 16:40:55 +00:00
2021-02-06 04:42:36 +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).
2020-02-17 16:40:55 +00:00
− 25329− 6513273− 18− 4 8
2021-02-06 04:42:36 +00:00
Now, let us repeat the search, but on a much larger scale:
2020-02-17 16:40:55 +00:00
2021-02-06 04:42:36 +00:00
First, generate four million pseudo-random numbers using a specific form of what is known as a "Lagged Fibonacci Generator":
2020-02-17 16:40:55 +00:00
2021-02-06 04:42:36 +00:00
For 1 ≤ k ≤ 55, sk = \[100003 − 200003k + 300007k3] (modulo 1000000) − 500000. For 56 ≤ k ≤ 4000000, sk = \[sk− 24 + sk− 55 + 1000000] (modulo 1000000) − 500000.
2020-02-17 16:40:55 +00:00
2021-02-06 04:42:36 +00:00
Thus, s10 = − 393027 and s100 = 86613.
2020-02-17 16:40:55 +00:00
2021-02-06 04:42:36 +00:00
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.
2020-02-17 16:40:55 +00:00
2021-02-06 04:42:36 +00:00
Finally, find the greatest sum of (any number of) adjacent entries in any direction (horizontal, vertical, diagonal or anti-diagonal).
2018-10-10 22:03:03 +00:00
2020-12-16 07:37:30 +00:00
# --hints--
2018-10-10 22:03:03 +00:00
2021-02-06 04:42:36 +00:00
`euler149()` should return 52852124.
2018-10-10 22:03:03 +00:00
```js
2020-12-16 07:37:30 +00:00
assert.strictEqual(euler149(), 52852124);
2018-10-10 22:03:03 +00:00
```
2021-01-13 02:31:00 +00:00
# --seed--
## --seed-contents--
```js
function euler149() {
return true;
}
euler149();
```
2020-12-16 07:37:30 +00:00
# --solutions--
2020-08-13 15:24:35 +00:00
2021-01-13 02:31:00 +00:00
```js
// solution required
```