Help to understand the shell game solution

I am having trouble understanding the shell game solution on this page:

There is a slower python version solution here which is much easier to understand:

Can someone help to explain how we come up with the solution on useco.guide?

Thanks,
Baoshan