s =1.0# initial partx =1# the numerator 1k =0# iteratorrepeat {
k <- k +1# current iterator x <- x / k # the fractional part s <- s + x # sum the two partsif (x <1e-10) { # control the accuracy break
}
}
stringr::str_glue("After {k} iterations, the resuling e is: {s}")
## After 14 iterations, the resuling e is: 2.71828182845823