From 3f31f6b14c38d6536d0ff14bfaaf2f9334850441 Mon Sep 17 00:00:00 2001 From: katryamucaca Date: Sun, 12 Oct 2025 11:13:19 +0300 Subject: [PATCH] feat: solution --- cachematrix.R | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/cachematrix.R b/cachematrix.R index a50be65aa4..bfec70037b 100644 --- a/cachematrix.R +++ b/cachematrix.R @@ -1,15 +1,26 @@ -## Put comments here that give an overall description of what your -## functions do - -## Write a short comment describing this function - -makeCacheMatrix <- function(x = matrix()) { - +makeCacheMatrix <- function(x = matrix()){ + inversa <- NULL + set <- function(y){ + x <<- y + inv <<- NULL + } + get <- function() {x} + setInverse <- function(inverse) {inversa <<- inverse} + getInverse <- function() {inversa} + list(set = set, + get = get, + setInverse = setInverse, + getInverse = getInverse) } - -## Write a short comment describing this function - -cacheSolve <- function(x, ...) { - ## Return a matrix that is the inverse of 'x' -} +cacheSolve <- function(x, ...){ + inversa <- x$getInverse() + if(!is.null(inversa)){ + message("getting cached data") + return(inversa) + } + matris <- x$get() + inversa <- solve(matris, ...) + x$setInverse(inversa) + inv +} \ No newline at end of file