This is a very inefficient way to write this. Moreover, it would probably be easier to write a general function and use recursion. That being said, specifically falculating 12 factorial using a loop, we pre-populate the answer with \(1\) as it is the multiplicative identity.
fact12 <- 1
for (i in seq_len(12)){
fact12 <- fact12 * i
}
fact12 == factorial(12L)
## [1] TRUE
seq(from = 20L, to = 50L, by = 5L)
## [1] 20 25 30 35 40 45 50
Note that overwriting an existing R function is poor practice.
factorial <- function(a, b, c){
determinant <- sqrt(b ^ 2 - 4 * a * c)
denominator <- 2 * a
return(list(MorePositiveRoot = (-b + determinant) / denominator,
LessPositiveRoot = (-b - determinant) / denominator))
}
\(x^2 + 8x + 15\) has the roots \((-3, -5)\) since it factors into \((x+3)(x+5)\)
factorial(1, 8, 15)
## $MorePositiveRoot
## [1] -3
##
## $LessPositiveRoot
## [1] -5