← Complete problem index

PROJECT EULER · #0149

Maximum-sum Subsequence

Statement only · SolvedOriginal problem ↗

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).

2532
9651
3273
1848

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":

For 1k55, sk=[100003200003k+300007k3](mod1000000)500000.
For 56k4000000, sk=[sk24+sk55+1000000](mod1000000)500000.

Thus, s10=393027 and s100=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.

Finally, find the greatest sum of (any number of) adjacent entries in any direction (horizontal, vertical, diagonal or anti-diagonal).

Write-up coming later

The complete problem is available here. An approach, code, and answer will be added later.