+ 13
[challenge] estimate Pi with Monte Carlo Method � 🎰� 🎰� 🎰� 🎰
Given a circle with radius r and middlepoint x,y Given a square wiht length 2r and same middlepoint as circle The area of the circle is r^2 * PI The area of the square is 4r^2 Hence the ratio area of circle / area of square is Pi/4 How to program that? Randomly create about 20000 points within the square. How many of them are points inside the circle? Figure the ration mentioned above and multiply with 4. It should be about PI Hint: a point is in the circle, if the distance to middlepo
9 Respuestas
+ 15
+ 11
This reminds me the awesome animation by Calvin:
https://code.sololearn.com/WHOsWK01C9yY/?ref=app
+ 9
Here an easy version in Python
https://code.sololearn.com/cAnX34L9y43h
+ 6
https://code.sololearn.com/WyALDISxigXf/?ref=app
+ 4
PI approximation
https://code.sololearn.com/W311eN8KhKqe/?ref=app
+ 3
another python approximation
https://code.sololearn.com/cE0T5Jl1r1l9/?ref=app
+ 3
https://code.sololearn.com/WTGcnhKhE8W4/?ref=app
0
hai