Implement cacheSolve for square matrices