Alone in Napoli | R bloggers

- Advertisement -

[This article was first published on R – Xi’an’s Og, and kindly contributed to R-bloggers], (You can report content on this page here) Want to share your content on R-Bloggers? Click here if you have a blog, or click here if you don’t have one.

A combinatorics puzzle about a Napoli solitaire from The Riddler where 4 x 10 cards numbered from 1 to 10 are shuffled and when the number (1,2, or 3) moves to its position modulo 3 (1,2 or 1 ,2 or 3), the game is lost. 3). A simple R code shows that the probability of winning is approximately 0.00831:

- Advertisement -

N=40 for(t in 1:1e6)F=F+!sum(!(sample((1:N)%%10)-(1:N)%%3))

ChatGPT bends over backwards to achieve this figure! Now, the exact probability can be found by combinatorics. While there are 40! 40 ways of permuting the cards, which are not coincidences are

- Advertisement -

\sum\limits_{k=0}^4\sum\limits_{j=0}^4\sum\limits_{i=0}^4{13\choose i}{13\choose 4-i}{14\ choose j}{13-i\choose 4-j}{14-j\choose k}{9+i\choose 4-k}

Multiply by 4!4!4!28! (which I initially forgot), resulting in 0.00831:

- Advertisement -

for(i in 0:4)for(j in 0:4)for(k in 0:4) F=F+exp(lchoose(13,i)+lchoose(13,4-i)+3*lfactorial( 4)+ lchoose(14,j)+lchoose(13-i,4-j)+lfactorial(28)+ lchoose(14-j,k)+lchoose(9+i,4-k)-lfactorial(40) )


Source link

- Advertisement -

Recent Articles

Related Stories