Saturday, May 11, 2013

project euler problem 166

Criss Cross

A not-so-interesting problem since most part of the problem is about brute force, but there is still something that we can explore.  My old code needs 9.5 second to get the correct answer. I did not consider too much about how to stop the search if something is already invalid. So it is kind of pure brute force. This time I restricted the number of variables in the game to 8.  The code runs much faster, only 0.26 second needed.

Update: I thought it over, there are two other symmetric properties that we may take advantage of. I would like to omit the first one since it is relative easy to find.  The second is along the main diagonal in the very early stage of your loops. For example, a_{1,2} and a_{2,1} are symmetric. I changed my code just a little bit, the run time reduced to 0.144 second. Not bad!

No comments:

Post a Comment