News for hackers. Stuff that matters.
Re:Pi from High School Maths by molticrystal on Tuesday February 09, 2021 @12:02PM (#26079811)
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

[1] https://ogden.eu/pi/

Re:Pi from High School Maths by schoen on Tuesday February 09, 2021 @08:24PM (#26084788)
Another 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. :-)