Yes. You can take the original matrix A and rotate it to all possible configurations A ', A' 'and A' ''. Then you can sort them using your sort (just be sequential), select the first and hash using any hash function of your choice (again, the actual hash function doesn't matter, just be sequential).
Obviously, this can be optimized to a large extent without performing a full rotation and sorting - you can make comparisons lazily, stopping as soon as you know which rotation is sorted first - but the principle is the same.
Mark byers
source share