Created
February 7, 2018 16:48
-
-
Save SimonCoulombe/19e3ba2ae9c9c52bc8626fd0282bcc8b to your computer and use it in GitHub Desktop.
fermat's library pick 2.718 numbers implemented in R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
set.seed(2718) | |
picks <- function(){ | |
x <- 0; i <- 0 | |
while(x <1){ | |
i <- i+1 | |
x <- x + runif(n=1,min=0,max=1) | |
} | |
return (i) | |
} | |
myseq <- seq(1:100000) %>% as_tibble() %>% | |
rowwise() %>% | |
mutate(iter = picks()) %>% | |
ungroup() %>% | |
mutate(x = row_number(), | |
cummean = cumsum(iter) / row_number()) | |
myseq %>% | |
ggplot()+ | |
geom_line(aes(x= x, y = cummean),color="blue")+ | |
geom_line(aes(x=x, y= exp(1))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment