Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
17
Task/Monte-Carlo-methods/Lua/monte-carlo-methods.lua
Normal file
17
Task/Monte-Carlo-methods/Lua/monte-carlo-methods.lua
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
function MonteCarlo ( n_throws )
|
||||
math.randomseed( os.time() )
|
||||
|
||||
n_inside = 0
|
||||
for i = 1, n_throws do
|
||||
if math.random()^2 + math.random()^2 <= 1.0 then
|
||||
n_inside = n_inside + 1
|
||||
end
|
||||
end
|
||||
|
||||
return 4 * n_inside / n_throws
|
||||
end
|
||||
|
||||
print( MonteCarlo( 10000 ) )
|
||||
print( MonteCarlo( 100000 ) )
|
||||
print( MonteCarlo( 1000000 ) )
|
||||
print( MonteCarlo( 10000000 ) )
|
||||
Loading…
Add table
Add a link
Reference in a new issue