cachematrix.R solution