Anonymous user
Monte Carlo methods: Difference between revisions
m
→{{header|REXX}}: optimized the inner DO loop.
m (→{{header|F#}}: edited name) |
m (→{{header|REXX}}: optimized the inner DO loop.) |
||
Line 1,929:
if times=='' | times=="," then times=5000000000 /*five billion should do it, hopefully.*/
if chunk=='' | chunk=="." then chunk= 10000 /*perform Monte Carlo in 10k chunks.*/
limit=10000
limitSq=limit**2 /*··· so, instead of one, use limit**2.*/
accur=0 /*accuracy of Monte Carlo pi (so far).
!=0; @reps= 'repetitions: Monte Carlo pi is' /*pi decimal digit accuracy (so far).*/
say /*a blank line, just for the eyeballs.*/
do j=1 for times % chunk
do chunk /*do Monte Carlo, one chunk at-a-time.*/
if random(
end /*chunk*/
reps=chunk * j /*calculate the number of repetitions. */
_=compare(4*! / reps, pi) /*compare apples and ··· crabapples. */
if _<=accur then iterate /*
say right(comma(reps), 20) @reps 'accurate to' _-1 "places." /*
accur=_ /*use this accuracy for next baseline. */
end /*j*/
|