Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
12
Task/Monte-Carlo-methods/OCaml/monte-carlo-methods.ocaml
Normal file
12
Task/Monte-Carlo-methods/OCaml/monte-carlo-methods.ocaml
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
let get_pi throws =
|
||||
let rec helper i count =
|
||||
if i = throws then count
|
||||
else
|
||||
let rand_x = Random.float 2.0 -. 1.0
|
||||
and rand_y = Random.float 2.0 -. 1.0 in
|
||||
let dist = sqrt (rand_x *. rand_x +. rand_y *. rand_y) in
|
||||
if dist < 1.0 then
|
||||
helper (i+1) (count+1)
|
||||
else
|
||||
helper (i+1) count
|
||||
in float (4 * helper 0 0) /. float throws
|
||||
Loading…
Add table
Add a link
Reference in a new issue