fork download
  1. function monte_carlo_simulation(iterations)
  2. inside_circle = 0
  3. for _ in 1:iterations
  4. x, y = rand(), rand()
  5. if x^2 + y^2 <= 1
  6. inside_circle += 1
  7. end
  8. end
  9. return (inside_circle / iterations) * 4
  10. end
  11.  
  12. # Configuración
  13. iterations = 1_000_000
  14.  
  15. # Ejecución con temporizador
  16. @time pi_estimate = monte_carlo_simulation(iterations)
  17.  
  18. # Resultados
  19. println("Estimación de Pi: ", pi_estimate)
  20.  
Success #stdin #stdout 0.41s 214736KB
stdin
Standard input is empty
stdout
  0.028453 seconds (47.30 k allocations: 2.610 MiB, 84.01% compilation time)
Estimación de Pi: 3.140628