# Asher’s enigma

July 25, 2010
By

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

On his Probability and statistics blog, Matt Asher put a funny question (with my rephrasing):

Take a unit square. Now pick two spots at random along the perimeter, uniformly. For each of these two locations, pick another random point from one of the three other sides of the square and draw the segment. What is the probability the two segments intersect? And what is the distribution for the intersection points?

The (my) intuition for the first question was 1/2, but a quick computation led to another answer. The key to the computation is to distinguish whether or not both segments share one side of the square. They do with probability $dfrac{2}{4}times 1 + dfrac{2}{4}timesdfrac{2}{3} = dfrac{5}{6},$

in which case they intersect with probability 1/2. They occupy the four sides with probability 1/6, in which case they intersect with probability 1/3. So the final answer is 17/36 (as posted by several readers and empirically found by Matt). The second question is much more tricky: the histogram of the distribution of the coordinates is peaked towards the boundaries, thus reminding me of an arc-sine distribution, but there is a bump in the middle as well. Computing the coordinates of the intersection depending on the respective positions of the endpoints of both segments and simulating those distributions led me to histograms that looked either like beta B(a,a) distributions, or like beta B(1,a) distributions, or like beta B(a,1) distributions… Not exactly, though. So not even a mixture of beta distributions is enough to explain the distribution of the intersection points… For instance, the intersection points corresponding to segments were both segments start from the same side and end up in the opposite side are distributed as $dfrac{u_1(u_4-u_3)-u_3(u_2-u_1)}{u_4-u_3-u_2+u_1}$

where all u‘s are uniform on (0,1) and under the constraint $(u_2-u_1)(u_4-u_3)<0$. The following graph shows how well a beta distribution fits in that case. (Not perfectly, though!) The R code is

u=matrix(runif(4*10^5),ncol=4)
u[,c(1,3)]=t(apply(u[,c(1,3)],1,sort))
u[,c(2,4)]=-t(apply(-u[,c(2,4)],1,sort))
y=(u[,1]*(u[,4]-u[,3])-u[,3]*(u[,2]-u[,1]))/(u[,1]+u[,4]-u[,2]-u[,3])

Similarly, if the two segments start from the same side but end up on different sides, the distribution of one coordinate is given by $dfrac{u_1(1-u_3)-u_3u_4(u_2-u_1)}{1-u_3-u_4(u_2-u_1)}$

under the constraint $u_3. The outcome is once again almost distributed as a beta: The corresponding R code is

u=matrix(runif(4*10^5),ncol=4)
u[,c(1,3)]=-t(apply(-u[,c(1,3)],1,sort))
y=(u[,1]*(1-u[,3])-u[,3]*u[,4]*(u[,2]-u[,1]))/(1-u[,3]-u[,4]*(u[,2]-u[,1]))

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Tags: , , , , ,
{"ft_lang_label":"__label__en","ft_lang_prob":0.9062461,"math_prob":0.98791206,"size":2884,"snap":"2019-51-2020-05","text_gpt3_token_len":738,"char_repetition_ratio":0.13263889,"word_repetition_ratio":0.097222224,"special_character_ratio":0.26490983,"punctuation_ratio":0.144427,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9959613,"pos_list":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14],"im_url_duplicate_count":[null,null,null,null,null,null,null,3,null,null,null,null,null,3,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-01-21T09:01:43Z\",\"WARC-Record-ID\":\"<urn:uuid:548e957e-1220-4607-ad9f-05b0889261cd>\",\"Content-Length\":\"167707\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:78fd3d43-53fc-4e01-b4d7-2b002ff481a2>\",\"WARC-Concurrent-To\":\"<urn:uuid:10a734d6-2107-4f81-b4aa-3430f8f4e78e>\",\"WARC-IP-Address\":\"104.28.9.205\",\"WARC-Target-URI\":\"https://www.r-bloggers.com/asher%E2%80%99s-enigma/\",\"WARC-Payload-Digest\":\"sha1:CARQKFHV6IYBMTXVKNOKLEHDHNKAG3XM\",\"WARC-Block-Digest\":\"sha1:FL53EPCHZELDX4SPD7UYJOALNPNZYYXF\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-05/CC-MAIN-2020-05_segments_1579250601628.36_warc_CC-MAIN-20200121074002-20200121103002-00122.warc.gz\"}"}