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.39s 214684KB
stdin
Standard input is empty
stdout
  0.066223 seconds (47.30 k allocations: 2.610 MiB, 93.46% compilation time)
Estimación de Pi: 3.140432