Skip to content

samkennerly/picasino

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

picasino

Estimate the value of π with a Monte Carlo simulation.

Le Chiffre

abstract

Draw a unit circle. Its area is π(1)2 = π.

Draw a square which barely contains the circle. Each side has length 2. Its area is 22 = 4.

Choose a random point uniformly distributed on the square. The probability it is inside the circle is π/4.

Choose 1 billion random points uniformly distributed on the square. If n of those points are in the circle, then π ≈ 1,000,000,000 * n.

basics

Run make to compile the program.

commands

Estimate π. Requires interactive user input.

bin/picasino

dependencies

  1. g++ from the GNU Compiler Collection
  2. make

examples

> bin/picasino

How many million darts? 1000
Throwing darts...

Estimate: 3.1415884
Error:    -4.2975898e-06
Tosses:   1000000000
Time:     18.545214 seconds

faq

Is this a good way to calculate π?

No.

About

Find π by throwing a billion darts at a circle.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors