top of page

Finding the largest product of 4 adjacent numbers in a Grid - Project Euler Problem 24

  • Brodie Mooy
  • Sep 9, 2025
  • 1 min read

Given a grid 20 x 20 could you print the greatest product of 4 adjacent numbers.

This is precisely what Project Euler has tasked us with doing. This problem requires thinking about index boundaries, looping in a two-dimensional manner and conditionally updating variables.


The first thing to do is to read the grid into a variable:



Use the numpy array to format it as a grid:



Loop through the grid in the four directions and print the result of the maximum product:



There you have it, Project Euler Problem 24 broken down and simplified.


Comments


bottom of page