项目作者: samkennerly

项目描述 :
Find π by throwing a billion darts at a circle.
高级语言: C++
项目地址: git://github.com/samkennerly/picasino.git
创建时间: 2015-07-13T01:42:17Z
项目社区:https://github.com/samkennerly/picasino

开源协议:GNU General Public License v2.0

下载


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.

  1. bin/picasino

dependencies

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

examples

  1. > bin/picasino
  2. How many million darts? 1000
  3. Throwing darts...
  4. Estimate: 3.1415884
  5. Error: -4.2975898e-06
  6. Tosses: 1000000000
  7. Time: 18.545214 seconds

faq

Is this a good way to calculate π?

No.