#WeHateMath Project Euler 11 – Largest Product in a Grid

In the 20 X 20 grid below, four numbers along a diagonal line have been marked in red.


The product of these numbers is 26 63 78 14 = 1788696.

What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 2020 grid?



This is the first Project Euler problem that has personally offended me. That may seem strange but it’s because this is at it’s core an arithmetic problem, not math. At first glance, it seems similar to Euler problem 8, but it’s really a brute-force, grind-out-every-product-and-compare-them, ugly, arithmetic problem. So while I would have preferred a more elegant solution (a scalpel instead of a hammer, as it were), I went with the ugly one.

The perfect programming language for ugly, brute-force hammer solutions is C, so that’s what I used. (I considered Fortran, which is actually better for brute-force math and arithmetic problems but the last time I used it was in 1977).

So when I ground out the answer, here’s what I got:

MacPro15:WeHateMath tsinclair$ time ./Project_Euler11


So it only took about 3-thousandths of a second to get my answer, but I’m still annoyed.


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 )

Google+ photo

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

Twitter picture

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

Facebook photo

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

Connecting to %s