Implement cachematrix solution