Project Euler 11

I just finished this one.  My code is incredibly huge, over 100 lines.  I’ve seen a few solutions that were far shorter than mine, but I found the answer.  It took me a half hour to realize this, but for those who are trying to solve this and are stuck, don’t forget to check the correct diagonal directions.  I was checking diagonally down from left to right, and then checking diagonally up from right to left, which is the exact same thing.  That produced the exact same results, so I had to change one of those checks.

Here are a couple other hints, that most of you probably understood right away:

  1. Checking the products from left to right will yield the same result as checking them from right to left, so don’t do both checks.
  2. Checking the products from top to bottom will yield the same result as checking them from bottom to top, so don’t do both checks.
  3. If any of the numbers are 0, then the product will result in 0, so you can skip testing those before you even find the product.

I used a 2-dimensional array to solve this problem, which gave me an easy-to-visualize x and y axis.  Another option is to use a 1-dimensional array and perform % 20 on each index to find one of the axes.  I’ll leave it up to you to figure out how to find the other axis.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s