• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

euler 11

 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i seem to be having a similar problem with this one as i had for euler 81
the answer is in the ballpark but is significantly less than correct answer. the other thing they have in common is they use the same method to populate the array(hence i suspect that method but see nothing wrong with it).

i get answer 51267216
correct answer is 70600674

an unrelated question. do you like the try catch block where it is, or do you think it would be better inside the readData() method?
i noticed i had an int called sum that is actually a product...i changed it.
 
Sheriff
Posts: 3036
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you're missing a diagonal. One goes down-right and the other goes up-left, which are really the same thing from different ends. You want a down-right and a down-left.

Also, product, not sum!
 
Marshal
Posts: 73292
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For this sort of thing, you always ought to write the algorithm on paper before trying any coding.
I don’t like that try-catch I am afraid.
You need a finally (or try-with-resources) to make sure the reader is properly closed. I don’t know whether you can use try-with-resources without a catch or finally following; I have never tried. You may have to re-throw the Exception; in fact, since you are not taking any action to recover from the Exception, you might as well re-throw it all the way to the main method and terminate the JVM.
Why on earth are you using String[][] arrays rather than int[][]? That is not the sort of thing Strings were intended for at all
 
Randall Twede
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
solved it, and #81 as well. i was missing a diagonal(in a way).
if(i - 3 < size && j - 3 >= 0)
should have been
if(i + 3 < size && j - 3 >= 0)
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic