fork download
  1. monte_carlo_simulation <- function(iterations) {
  2. inside_circle <- 0
  3. for (i in 1:iterations) {
  4. x <- runif(1)
  5. y <- runif(1)
  6. if (x^2 + y^2 <= 1) {
  7. inside_circle <- inside_circle + 1
  8. }
  9. }
  10. return (inside_circle / iterations) * 4
  11. }
  12.  
  13. # Configuración
  14. iterations <- 1e6
  15. start_time <- proc.time()
  16.  
  17. # Ejecución
  18. pi_estimate <- monte_carlo_simulation(iterations)
  19.  
  20. # Tiempo final
  21. end_time <- proc.time()
  22.  
  23. # Resultados
  24. cat("Estimación de Pi:", pi_estimate, "\n")
  25. cat("Tiempo de ejecución:", (end_time - start_time)["elapsed"], "segundos\n")
  26. # your code goes here
Success #stdin #stdout #stderr 4.99s 48288KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
/bin/bash: line 15: 2087794 CPU time limit exceeded R --vanilla --quiet --slave --encoding=UTF-8 --file=/home/uDVYVq/prog.r > a.out