Wednesday, September 21, 2011

Project Euler 11 Solution



This one wasn't so hard. The difficulty was resisting the urge to make it sleeker.

A better way to do this (ah, hindsight) would be to have one loop and at each position in the 2d array do all the horizontal/vertical/diagonal math right then. It would have been a bit tricky to keep up with all the "are there enough numbers available to do this" checks that would have been needed.

This problem reminded me of the some time I was reading about object oriented programming - specifically about why the methodology is used. I had read that a class should contain a set of data and all the operations you would want to perform on that set. I could rewrite this program such that an initialized class would load up the relevant array and then the methods of that class would get each of the different products I'd need.

EDIT: I looked at the solutions other people created and it seems that this brute force method is very popular.

No comments:

Post a Comment