Anonymous user
Monte Carlo methods: Difference between revisions
m
→{{header|REXX}}: optimized the outer DO loop.
(→{{header|REXX}}: added a scale to show the number of (true) decimal digits of pi; added expanded output.) |
m (→{{header|REXX}}: optimized the outer DO loop.) |
||
Line 1,521:
limit=10000-1 /*REXX random generates only integers. */
limitSq=limit**2 /*··· so, instead of one, use limit**2.*/
!=0; @reps='repetitions: Monte Carlo pi is' /*pi decimal digit accuracy (so far).*/▼
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
Line 1,528:
if random(0,limit)**2 + random(0,limit)**2 <=limitSq then !=!+1
end /*chunk*/
reps=chunk*j /*
if _<=
say right(commas(reps),20) @reps 'accurate to' _-1 "places." /*-1 for dec. pt.*/
accur=_ /*use this accuracy for next baseline. */
|