Created
July 21, 2017 04:29
-
-
Save elnikkis/d79f8797cadf6419f79d1876286141ee 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
# coding: utf-8 | |
import random | |
import math | |
def fall(): | |
rad = random.random() * math.radians(360) | |
c = random.random() + math.fabs(math.cos(rad)) | |
if c > 1: | |
return 1 | |
else: | |
return 0 | |
N = 1000000 | |
cnt = 0 | |
all = 0 | |
while True: | |
all += N | |
for i in xrange(N): | |
cnt += fall() | |
print(cnt) | |
print(all) | |
print(float(cnt)/all) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment