John Luxbrand wrote:
Paul Clapham wrote:Okay. So the stack trace says the error is at line 120 in your code. It's hard to tell what line that is here, because you've chopped off the first few lines of your class. So which line is line 120?
Paul Clapham wrote:Your input assumed that the program would take the first two parameters from the command line and use them for something. But there's no code in the program which uses parameters from the command line. Instead there is code which assumes that a sequence of numbers will be typed into stdin, as in your "expected output" picture. Since you typed no numbers at all into stdin, the output was based on summing that (empty) set, which returns zero.
Paul Clapham wrote:Hi John, welcome to the Ranch!
It looks like the numbers you're working with, which look they come from somewhere outside the program, range from 1 to N. Am I right? I see some code which looks like it maps the range (1 ... N) to range (0 ... N-1), which is what you want to do to deal with Java's annoying zero-origin policy for arrays. But I see flaws in that mapping, for example line 30 shouldn't allow row 0. There may be others; perhaps you're doing the mapping twice in some cases? There's a lot of code and I haven't scanned it carefully.
Perhaps it would be better to have a class which encapsulates the Grid array and manages the mapping between the external 1-origin numbers and the internal 0-origin numbers? Otherwise you're going to find the mapping scattered all over the code, where you might forget to do it occasionally or you might do it twice accidentally.
Carey Brown wrote:Just a guess but it seems to me that you are not comparing to either the beginning (0) or the end (sizeOfGrid-1) correctly. You might try these changes.