4 ms·
Buffon's needle problem[0] remains my favorite way to calculate pi. You drop readily available sticks such as matches or toothpicks on top of parallel lines at
by molticrystal 6y ago
Buffon's needle problem[0] remains my favorite way to calculate pi. You drop readily available sticks such as matches or toothpicks on top of parallel lines at least slightly wider than the sticks. In a Monte Carlo fashion, pi will emerge. An interactive example is available[1].
pi is approximately:
(2 x the stick length * the number dropped)
divided by
(the distance between lines * sticks crossing a line)
[0] https://en.wikipedia.org/wiki/Buffon%27s_needle_problem https://en.wikipedia.org/wiki/Buffon%27s_needle_problem
[1] https://ogden.eu/pi/ https://ogden.eu/pi/
- schoen 6y agoAnother Monte Carlo angle: import random n=1000000 print(4.*sum(random.random()**2 + random.random()**2 < 1 for i in range(n))/n) Both this version and the Buffon's Needle version are a lot less efficient than the version in this article, because the article's version is making educated guesses about where the boundary is, while the randomized versions are making uneducated guesses. :-)