Skip to content

Instantly share code, notes, and snippets.

@alexhallam
Created June 24, 2021 19:32
Show Gist options
  • Save alexhallam/3091c3c25a65f19b6afa18aa23a23bb9 to your computer and use it in GitHub Desktop.
Save alexhallam/3091c3c25a65f19b6afa18aa23a23bb9 to your computer and use it in GitHub Desktop.
n <- 1e8
x <- runif(n)
y <- runif(n)
r = sqrt(x^2 + y^2)
data.frame(x,y,r) %>% mutate(in_circle = ifelse(r^2 <= 1, 1, 0)) %>%
summarise(4*sum(in_circle)/n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment