Skip to main content

Simulate probability of a needle crossing a line on a table after it fell on it

Project description

Simulation experiment with needles

Blogpost

Please consider to also read my blogpost on Medium.

Authors and Licensing

Motivation

The problem discussed here might seem random. But the aim of this package is to show that an apparently complex challenge can be broken down into mathematical expressions to answer a certain question.

Task

Imagine the following situation. You have a table with parallel lines on it. The distance between these lines is constant across the table.

And you have a needle. It can be any kind of needle, but if it makes things easier for you, just imagine the needle is a sewing needle. The needle has a certain length.

We would like to answer the following question: given the distance between the parallel lines on the table and the needle's length, what is the likelihood that the needle crosses a line on the table after it fell on it?

Installation

To install the package from PyPi yout have to execute the following.

python -m pip install drop-needle 

Functionality

After installation the package can be loaded.

from drop_needle.Table import Table

# Initialize a table with a distance of 10 between the lines
table = Table(10)

# Simulate 10,000 needles with a length of 7 falling on the table
table.simulate(10000, 7)
0.4401

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

drop_needle-0.2.tar.gz (3.2 kB view details)

Uploaded Source

File details

Details for the file drop_needle-0.2.tar.gz.

File metadata

  • Download URL: drop_needle-0.2.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.3

File hashes

Hashes for drop_needle-0.2.tar.gz
Algorithm Hash digest
SHA256 0da150aad91739d3f449a9f0657da76ae335aa6a8953a90b2593242ab085e538
MD5 d3532fdba5867f13d17a0b2903858e51
BLAKE2b-256 cd7fe731277174d68ba2cd75ae569ed61e0e5d54b47ddcfe168058203a1ac03a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page