I created a game app based on the “Buffon’s Needle” experiment from my previous post. What makes it interesting is the seemingly mysterious fact that you can approximate π simply by dropping needles onto parallel lines—without drawing a circle anywhere! This could also make a fun app-development exercise for junior high and high school students. So, let’s take a look at the app I created. For this kind of project, I usually use MIT App Inventor. In this case, the ImageSprite feature was especially useful, allowing me to implement the needle-dropping action quite nicely.
πの近似値3.14が得られるまで針を投げるゲームアプリ
これはゲームアプリの作成です。前報の「ビュフォンの針」に基づいていますが、少し仕様は異なります。でも、円周も描かないのに、平行線に針を投げるだけで、πの近似値が求められる不思議さを味わえます。中高生向けのアプリ開発例題にできるかもしれません。早速、作成したアプリを以下に示します。この種のアプリを作る場合、私はMIT App Inventorを使います。今回は、特にImageSpriteの機能を使って、針の投入をうまく書くことができました。


A quick note before going any further. Buffon’s needle experiment was originally designed to estimate π by tossing a large number of needles. This app, however, keeps tossing needles until it obtains 3.14—that is, π correct to two decimal places. Still, there may be some educational value in building the app yourself and experiencing the curious fact described above: π emerges simply by tossing needles onto parallel lines.
I have also added a small trick. Since the result depends on the sequence of random numbers, it is possible that the estimate may take quite a while to reach 3.14. So, somewhat secretly, I set the initial state as if 100 needles had already been tossed, with 64 of them crossing one of the red parallel lines. This gives a crossing probability of 0.64, corresponding to π = 3.125, which is already a fairly good estimate. So, in most cases, tossing just a few dozen more needles should be enough. In the example shown above, the estimate reached 3.14 after a total of 110 needle tosses.
For reference, let the distance between the parallel lines be D and the needle length be L. When D=L=1, as explained in the Doc above, π can be estimated as follows:
m=total number of needles tossed
n=number of needles crossing a parallel line
π≈2m/n
The best (m,n) pair I have found so far using this app is (m,n)=(8900,5666),which gives π≈2×8900/5666=3.1415, correct to four decimal places. With the help of AI, it would probably be easy to find many more such pairs—but that might take some of the fun out of it.
If you are interested in this app and would like to try it out, please contact me. I will provide the Android version (APK file).
0 件のコメント:
コメントを投稿