# Alone in Napoli | R bloggers

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:

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

$\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:

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

Connected