Created
January 29, 2015 05:35
-
-
Save seungha-kim/20d76b251b0d3cabdee1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Monte Carlo method | |
# http://en.wikipedia.org/wiki/Monte_Carlo_method | |
from random import random as rnd | |
from math import sqrt | |
trial = 1000000 | |
hit = 0 | |
for i in range(trial): | |
if sqrt(rnd()**2 + rnd()**2) < 1: | |
hit += 1 | |
print 1.0*hit/trial*4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment