-
-
Save originalsouth/bf54f5f91fed928abaf9df7bf2b33fb6 to your computer and use it in GitHub Desktop.
Calculate e by drawing random numbers
This file contains hidden or 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
#!/usr/bin/env julia | |
using Random | |
function play() | |
r=0.0 | |
counter=0.0 | |
while r<1.0 | |
r+=rand(Float64) | |
counter+=1.0 | |
end | |
return counter | |
end | |
function drive(N::Int64) | |
e=0.0 | |
for _ in 1:N | |
e+=play() | |
end | |
println(e/N) | |
end | |
@time drive(length(ARGS)==1 ? parse(Int64,ARGS[1]) : 1000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment