A French mathematician called Georges-Louis Leclerc, Comte de Buffon (1707-1788) started thinking about this and worked out the probability.
This probability is called “Buffon’s Needle” in his honor.
Buffon then used the results from his experiment with a needle to estimate the value of π (Pi). He worked out this formula:
π ≈ 2LN / CW
Where
- L is the length of the needle
- N is the total number of needles
- C is the total number of needles crossing a line
- W is the line spacing (Width of the wooden boards on the floor)
We have decided to simulate this experiment using a Python script (using Python Turtle).
Task 1
Run the above script and count how many needles (out of 50) are crossing a line. Apply Buffon’s formula to estimate the value of Pi using:
- L is the length of the needle (L = 30 pixels
- N is the total number of needles (N = 50 needles)
- C is the total number of needles crossing a line
- W is the line spacing (Width of the wooden boards on the floor W = 40 pixels)
Task 2
Adapt this Python script to automatically detect if a needle is crossing a line.
Your Python script should then count how many needles are crossing a line and use this to estimate a value of Pi.
Solution...
The solution for this challenge is available to full members!Find out how to become a member:
➤ Members' Area