Estimating Pi using Buffon’s Needle

Painting by François-Hubert Drouais - Musée Buffon à Montbard, France

Painting by François-Hubert Drouais – Musée Buffon à Montbard, France

A few hundred years ago people enjoyed betting on coins tossed on to a wooden floor … would they cross a line or not?

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:
π ≈ 2LN / CW

  • 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)

needle

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.

Share Button
Posted in Computer Science, Python - Advanced, Python Challenges Tagged with:

Our Latest Book