Contesting for Idiot du Jour
Jerry Jensen
jerry at jhjensen.com
Wed Sep 2 23:27:28 EDT 2020
1/2 is the right answer.
Take your drawing of the circles. Cut a verrrryy thin radial slice from the center to the outside circle. So thin that it is just a line.
Now think of how likely a random point on that line will be in the part of the line that was in the smaller circle. The part that was from the smaller circle is HALF as long as the entire line.
Now add up all the possible positions of that line. Why would that change the answer?
Congratulations, you understand integrals!
.Jerry
> On Sep 2, 2020, at 7:38 PM, Roger Guay via use-livecode <use-livecode at lists.runrev.com> wrote:
>
> Your chance to be Genius du Jour:
>
> If I construct 2 concentric circles, one being half the radius of the larger, then simple math shows that the smaller circle has an area ¼ the area of the larger.
> Now if I generate a random point within the radius of the larger circle, I should expect that the probability of it landing in the smaller circle to be ¼.
> But, I must be doing something wrong because I get ½ !
>
> Here is my script:
>
> on mouseDown
>
> getStuff
>
> end mouseDown
>
>
> local tR, tTheta, tX0, tY0, tX1, tY1, tTotCount, tL, tLongCount
>
> on getStuff
>
> put item 1 of the loc of grc OuterCircle into tx0
>
> put item 2 of the loc of grc OuterCircle into tY0
>
> put "" into tTotCount
>
> put "" into tLongCount
>
> emptyFlds
>
> end getStuff
>
>
> on mouseUp
>
> lock screen
>
> repeat 1000
>
> put random(200) into tR -- 200 is half the width of the larger circle
>
> if tR > 1 then
>
> ## put random(2*pi) into tTheta1
>
> get random(360)
>
> put it*pi/180 into tTheta1
>
> put tR*cos(tTheta1) into tX1
> put tR*sin(tTheta1) into tY1
>
> set the loc of grc Ptgrc to tX0 + tX1, tY0 - tY1 --- grc Ptgrc is a 2 pixle oval
>
> if intersect(grc Ptgrc, grc InnerCircle, "opaque Pixels") then add 1 to tLongCount
>
> add 1 to tTotCount
>
> end if
>
> end repeat
> put tTotCount into fld "totcountFld"
>
> put tLongCount into fld “LongCountFld"
>
> put tLongCount/tTotCount into fld "RatioFld"
>
> unlock screen
>
> end mouseUp
>
>
> Apparently, this does not generate a random point within the larger circle! Can someone please tell me what’s wrong here?
>
> Thanks,
> Roger
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
More information about the use-livecode
mailing list