Making use of the observation that Pi is the area of a circle with diameter equal to one, a brute force calculation of Pi would be to:
- randomly generate points in a square
- count the points within the circle and the total number of points
- multiple the ratio of points in the circle to total number of points by the area of a square with a side the length of the diameter of the circle (in this case two (2))
BruteForcePi.estimate_pi # Estimated value of π: 3.2 (accuracy: 98.1408%)
BruteForcePi.estimate_pi(iterations: 10_000) # Estimated value of π: 3.1164 (accuracy: 99.1981%)