Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Some addendum:

1. You can do one quadrant rather than four, then multiply that approximation by 4.

2. Montecarlo is good to develop an intuition about Monte carlo approximations but converges really slowly.

Ramanujan-Sato series for pi or Chudnovsky algorithm can be a scalable alternative, gives you a lot of digits.

Now... how many digits you usually need? Very few. Practical applications requiring more than 15 digits are hard to find. e.g: NASA uses 15 digits for interplanetary navigation, even for the most distant spacecraft such as the Voyager 1 which is now 20 billion kilometers from Earth.

Can just use a constant, or in the worst case, if missing, define it as:

    pi = arc tan (1) * 4


Accuracy from one quadrant and four quadrants would be the same, though, and full circle is easier to code (no extra conditions).

To get better accuracy you would need to cut out some parts that are clearly inside or outside the circle, and only throw the points in the areas where the circle can actually be.


Sure, that is equivalent to doing it on one quadrant with 4 times the dots and averaging it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: