A place to air possible concerns or difficulties in understanding ProjectEuler problems. This forum is not meant to publish solutions. This forum is NOT meant to discuss solution methods or giving hints how a problem can be solved.
Forum rules
As your posts will be visible to the general public you are requested to be thoughtful in not posting anything that might explicitly give away how to solve a particular problem.
This forum is NOT meant to discuss solution methods for a problem.
In particular don't post any code fragments or results.
Don't start begging others to give partial answers to problems
Don't ask for hints how to solve a problem
Don't start a new topic for a problem if there already exists one
Well, this problem's going to be a pain to troubleshoot. I may have to comment out most of my program, look at just a corner (maybe 20x20), and add a ton of test code to handle just this corner (which hopefully doesn't introduce different errors...).
Update: All right, finally got back to it. So far, it seems my horizontal and vertical sums are working correctly. I'm testing on the upper left 10x10 square (seems if I print in landscape, 10 numbers is about all that will fit per row...). So either I fouled up on the diagonals or mucked up a limit somewhere...
Can you check my results and tell which are wrong:
max in rows: 13414319
max in columns: 11593776
max in anti-diagonals: 10284763
max in diagonals: 10785046
find the greatest sum of (any number of) adjacent entries
Are you limiting yourself to whole rows/columns/diagonals? Because many numbers in the table are negative, the maximum sum of adjacent numbers in a row is often greater than the sum of the entire row.
I've been trying to squeeze the correct values out of that LFG. I am getting s[10] correctly, but for some weird reason s[100] is always -357419. I don't think there's an overflow. What could possibly go wrong with s[k] = ((s[k-24] + s[k-55] + 1000000) mod 1000000) - 500000?
Could someone be so kind and confirm or decline
s[17] = 134343,
s[55] = -1343089,
s[1000] = 355076,
s[123456] = -1414215?
const MAX_LENGTH = 4000000;
var s: array of longint;
k: longint;
begin
setlength(s, MAX_LENGTH+1);
{ LFG: fill array }
for k := 1 to 55 do
s[k] := ((100003 - 200003*k + 300007*k*k*k) mod 1000000) - 500000;
for k := 56 to MAX_LENGTH do
s[k] := ((s[k-24] + s[k-55] + 1000000) mod 1000000) - 500000;
end.
I don't think I'm giving anything else away but the things which are already in the description. Though I can't seem to locate the error
leghorn wrote:I've been trying to squeeze the correct values out of that LFG. I am getting s[10] correctly, but for some weird reason s[100] is always -357419. I don't think there's an overflow. What could possibly go wrong with s[k] = ((s[k-24] + s[k-55] + 1000000) mod 1000000) - 500000?
Could someone be so kind and confirm or decline
s[17] = 134343,
s[55] = -1343089,
s[1000] = 355076,
s[123456] = -1414215?
There is an overflow. These are the numbers you get if you use signed 32bit integers everywhere, but for example 300007*k*k*k already overflows for k>24.
Since I've read that in several publications... Do you, too, consider the maximum subsequence sum = 0 if all items in that sequence are < 0?
cska wrote:Can you check my results and tell which are wrong:
max in rows: 13414319
max in columns: 11593776
max in anti-diagonals: 10284763
max in diagonals: 10785046
Speaking of rows, I get xxxx2415. Sound reasonable?