From 3215ae342e211200112021ab59bf4938fb696188 Mon Sep 17 00:00:00 2001 From: blue-055 Date: Sat, 20 Jun 2026 17:32:32 -0400 Subject: [PATCH 1/2] solution --- cachematrix.R | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/cachematrix.R b/cachematrix.R index a50be65aa44..b4a15cf2620 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -1,15 +1,29 @@ -## Put comments here that give an overall description of what your -## functions do - -## Write a short comment describing this function - -makeCacheMatrix <- function(x = matrix()) { - -} - - -## Write a short comment describing this function - +#making Cache Matrix cacheSolve <- function(x, ...) { ## Return a matrix that is the inverse of 'x' } +makeCacheMatrix <- function(x = matrix(sample(1:100,9),3,3)) { + s <- NULL + set <- function(y) { + x <<- y + s <<- NULL + } + get <- function() x + setsolve <- function(solve) s <<- solve + getsolve <- function() s + list(set = set, get = get, + setsolve = setsolve, + getsolve = getsolve) +} +#solving cache +CacheSolve <- function(x, ...) { + s <- x$getsolve() + if(!is.null(s)) { + message("getting inversed matrix") + return(s) + } + data <- x$get() + s <- solve(data, ...) + x$setsolve(s) + s +} \ No newline at end of file From 6f9188e9de8839af8618b9d51a70b744015ae8cd Mon Sep 17 00:00:00 2001 From: blue-055 Date: Sat, 20 Jun 2026 17:35:29 -0400 Subject: [PATCH 2/2] Update cachematrix.R --- cachematrix.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cachematrix.R b/cachematrix.R index b4a15cf2620..f25c8415ea3 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -26,4 +26,4 @@ CacheSolve <- function(x, ...) { s <- solve(data, ...) x$setsolve(s) s -} \ No newline at end of file +}