Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
24
Task/Monte-Carlo-methods/PureBasic/monte-carlo-methods.basic
Normal file
24
Task/Monte-Carlo-methods/PureBasic/monte-carlo-methods.basic
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
OpenConsole()
|
||||
|
||||
Procedure.d MonteCarloPi(throws.d)
|
||||
inCircle.d = 0
|
||||
For i = 1 To throws.d
|
||||
randX.d = (Random(2147483647)/2147483647)*2-1
|
||||
randY.d = (Random(2147483647)/2147483647)*2-1
|
||||
dist.d = Sqr(randX.d*randX.d + randY.d*randY.d)
|
||||
If dist.d < 1
|
||||
inCircle = inCircle + 1
|
||||
EndIf
|
||||
Next i
|
||||
pi.d = (4 * inCircle / throws.d)
|
||||
ProcedureReturn pi.d
|
||||
|
||||
EndProcedure
|
||||
|
||||
PrintN ("'built-in' #Pi = " + StrD(#PI,20))
|
||||
PrintN ("MonteCarloPi(10000) = " + StrD(MonteCarloPi(10000),20))
|
||||
PrintN ("MonteCarloPi(100000) = " + StrD(MonteCarloPi(100000),20))
|
||||
PrintN ("MonteCarloPi(1000000) = " + StrD(MonteCarloPi(1000000),20))
|
||||
PrintN ("MonteCarloPi(10000000) = " + StrD(MonteCarloPi(10000000),20))
|
||||
|
||||
PrintN("Press any key"): Repeat: Until Inkey() <> ""
|
||||
Loading…
Add table
Add a link
Reference in a new issue