Project Euler: Problem 11

Dec 26, 2025

🚨

Spoiler alert: This post contains spoilers for Project Euler.

Problem 11

projecteuler p11 (light) Largest Product in a Grid

Approach

There are two ways to check each set of 4 numbers that I can see.

The first approach would use three for-loops. One each that scans horizontally, vertically, and a 3rd that scans both the left-to-right diagonal and right-to-left diagonal.

The second approach would visit each number and compute all of the valid sets of 4 numbers that it is apart of. For instance, the top-left-most number is part of a horizontal, vertical, and left-to-right diagonal. This approach will result in shorter, but less readable code I think.

We'll go with the first approach for readability.

JS Solution

Conclusion

Looking at the forums, brute force is a pretty common approach here. There are some small optimizations you can make, such as skipping sets that contain a number smaller than 10. But there doesn't seem to be a magic solution that avoids a mostly exhaustive search.

Final answer

7060067470600674

Ryan McIntire