[This article was first published on Freakonometrics - Tag - R-english, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
To be honest, I did not understood the answer on the blog, but if we write it down, we want to solve
> 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
> 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 31Thus, given
To leave a comment for the author, please follow the link and comment on their blog: Freakonometrics - Tag - R-english.
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.