Create longest possible way in X by Y field. This way can not cross itself or have 2x2 square. ... is number of possible ways this program has got in list. When this number hits 0, the program will be finished.
This program can have some bugs, please write in comments for which parameters you get odd result. 5*5 - 1 second 6*6 - 43 seconds 7*7 - breaks limit of 200000 elements in list :C