Even odds

January 22, 2012
By

(This article was first published on Freakonometrics - Tag - R-english, and kindly contributed to R-bloggers)

This evening, I found a nice probabilistic puzzle on http://www.futilitycloset.com/ "A bag contains 16 billiard balls, some white and some black. You draw two balls at the same time. It is equally likely that the two will be the same color as different colors. What is the proportion of colors within the bag?"
To be honest, I did not understood the answer on the blog, but if we write it down, we want to solve
http://i1.wp.com/freakonometrics.blog.free.fr/public/perso5/futil-01.gif?w=456
Let us count: if http://i0.wp.com/freakonometrics.blog.free.fr/public/perso5/futil-04.gif?w=456 is the total number of balls, and if http://i0.wp.com/freakonometrics.blog.free.fr/public/perso5/futil-03.gif?w=456 is the number of white http://i2.wp.com/freakonometrics.blog.free.fr/public/perso5/futil-05.gif?w=456 balls then
http://freakonometrics.blog.free.fr/public/perso5/cccccwwwwwww.gif
I.e. we want to solve a polynomial equation (of order 2) in http://i1.wp.com/freakonometrics.blog.free.fr/public/perso5/futil-07.gif?w=456, or to be more precise, in  http://i0.wp.com/freakonometrics.blog.free.fr/public/perso5/futil-00.gif?w=456
http://i0.wp.com/freakonometrics.blog.free.fr/public/perso5/futil-06.gif?w=456
If http://i0.wp.com/freakonometrics.blog.free.fr/public/perso5/futil-04.gif?w=456 is equal to 16, then http://i0.wp.com/freakonometrics.blog.free.fr/public/perso5/futil-03.gif?w=456 is either 6 or 10. It can be visualized below
> balls=function(n=16){
+ NB=rep(NA,n)
+ for(k in 2:(n-2)){
+ NB[k]=(k*(k-1)+(n-k)*(n-k-1))
+ }
+ k=which(NB==n*(n-1)/2)
+ if(length(k)>0){
+ plot(1:n,NB,type="b")
+ abline(h=n*(n-1)/2,col="red")
+ points((1:n)[k],NB[k],pch=19,col="red")}
+ return((1:n)[k])}
> balls()
[1] 6 10

But more generally, we can seek other http://i0.wp.com/freakonometrics.blog.free.fr/public/perso5/futil-04.gif?w=456's and other pairs of solutions of such a problem. I am not good in arithmetic, so let us run some codes. And what we get is quite nice: if http://i1.wp.com/freakonometrics.blog.free.fr/public/perso5/futil-10.gif?w=456 admits a pair of solutions, then http://i1.wp.com/freakonometrics.blog.free.fr/public/perso5/futil-10.gif?w=456 is the squared of another integer, say http://i2.wp.com/freakonometrics.blog.free.fr/public/perso5/futil-13.gif?w=456. Further, the difference between http://i2.wp.com/freakonometrics.blog.free.fr/public/perso5/futil-11.gif?w=456 and http://i1.wp.com/freakonometrics.blog.free.fr/public/perso5/futil-12.gif?w=456 is precisely http://i2.wp.com/freakonometrics.blog.free.fr/public/perso5/futil-13.gif?w=456. And http://i1.wp.com/freakonometrics.blog.free.fr/public/perso5/futil-12.gif?w=456 will be one of the answers when the total number of balls will be http://i0.wp.com/freakonometrics.blog.free.fr/public/perso5/futil-20.gif?w=456. Thus, recursively, it is extremely simple to get all possible answers. Below, we have http://i0.wp.com/freakonometrics.blog.free.fr/public/perso5/futil-04.gif?w=456, http://i0.wp.com/freakonometrics.blog.free.fr/public/perso5/futil-03.gif?w=456, http://i0.wp.com/freakonometrics.blog.free.fr/public/perso5/futil-21.gif?w=456 and the difference between http://i0.wp.com/freakonometrics.blog.free.fr/public/perso5/futil-21.gif?w=456 and http://i0.wp.com/freakonometrics.blog.free.fr/public/perso5/futil-03.gif?w=456,
> for(s in 4:1000){
+ b=balls(s)
+ if(length(b)>0) print(c(s,b,diff(b)))
+ }
[1] 9 3 6 3
[1] 16 6 10 4
[1] 25 10 15 5
[1] 36 15 21 6
[1] 49 21 28 7
[1] 64 28 36 8
[1] 81 36 45 9
[1] 100 45 55 10
[1] 121 55 66 11
[1] 144 66 78 12
[1] 169 78 91 13
[1] 196 91 105 14
[1] 225 105 120 15
[1] 256 120 136 16
[1] 289 136 153 17
[1] 324 153 171 18
[1] 361 171 190 19
[1] 400 190 210 20
[1] 441 210 231 21
[1] 484 231 253 22
[1] 529 253 276 23
[1] 576 276 300 24
[1] 625 300 325 25
[1] 676 325 351 26
[1] 729 351 378 27
[1] 784 378 406 28
[1] 841 406 435 29
[1] 900 435 465 30
[1] 961 465 496 31
Thus, given http://i1.wp.com/freakonometrics.blog.free.fr/public/perso5/futil-22.gif?w=456, consider an urn with http://i1.wp.com/freakonometrics.blog.free.fr/public/perso5/futil-23.gif?w=456 balls. We draw two balls at the same time. It is equally likely that the two will be the same color as different colors. Then the number of colors within the bag are respectively
http://i1.wp.com/freakonometrics.blog.free.fr/public/perso5/futil-24.gif?w=456
Finally, observe that the http://i2.wp.com/freakonometrics.blog.free.fr/public/perso5/futil-11.gif?w=456's are well known, from Pascal's triangle,

also known as triangular numbers,

http://freakonometrics.blog.free.fr/public/perso5/tr-pascal.gif

Maths can be magic, sometimes...

To leave a comment for the author, please follow the link and comment on his blog: Freakonometrics - Tag - R-english.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: , , , , ,

Comments are closed.