View Single Post
  #9  
Old 03-15-2008, 08:23 AM
SwampYankee's Avatar
SwampYankee SwampYankee is offline
New England Hick
 
Join Date: Sep 2006
Location: CT
Posts: 1,501
Quote:
Originally Posted by Matt L View Post
Aye, the "Monte Carlo" method for computing pi. Works fairly well. However, I recall reading about a closed-form solution a year or two ago. It only worked in binary (or another power of two, like hex) but that's good enough.

The point of the "Monte Carlo" algorithm is to throw dart at a 2x2 square, and of those darts that hit the square, count the number that are within a circle of radius 1. The area of the circle is pi, the area of the square is 4.

We must assume that "rand" returns a value between -1 and 1. Between 0 and 1 works too (I leave that as an exercise for the reader).
Yeah, that!
__________________

1980 300TD-China Blue/Blue MBTex-2nd Owner, 107K (Alt Blau) OBK #15
'06 Chevy Tahoe Z71 (for the wife & 4 kids, current mule) '03 Honda Odyssey (son #1's ride, reluctantly) '99 GMC Suburban (255K+ miles, semi-retired mule) 21' SeaRay Seville (summer escape pod)
Reply With Quote