alone in Napoli


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

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

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

\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}

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

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))

One Response to “alone in Napoli”

  1. […] article was first published on R – Xi’an’s Og, and kindly contributed to R-bloggers]. (You can report issue about the content on this page […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: