foshy.co.uk

Strip Jack Naked

05.01.2026     programming

Or Beggar-thy-neighbour has always held an odd fascination for me. This Wikipedia article is useful if you haven't come across the game.

I wanted to find out if it was possible for a game to go on ad infinitum. Or at least, to see how long a game could last. If an infinite game was possible, it would be amusing to setup the initial hands and then challenge someone to play. Wikipedia says the there are 653,534,134,886,878,245,000 initial states for the game, so perhaps one of those might cause a game to last forever.

Nine years ago I coded a simulation of the game and set it to play games and note the longest and shortest. It took about two or three hours to play 50,000 games - a reasonable sample size. The longest was a game of 2989 turns, and the shortest 38.

Believe it or not, I wasn't the only one thinking odd thoughts. In 2024 Brayden Casella used a lot of brain power and modern computing methods and found 30 distinct starting hands which are non terminating. These games all go through a cycle of 66 turns. This was brought to my attention by the marvellous Youtuber Matt Parker (links below). In a way Brayden and Matt have put an end to my curiosity, but I wanted to code the game in Javascript (which is easy to put online) and use one of the infinite starting positions and watch infinity unfold on my screen.

Having already coded the game in Processing I decided to be lazy and ask Google Gemini (AI) to make the game for me. It took seconds for the AI to come up with a working script (a bit humbling, as it takes me days and weeks to code anything), and then took me an hour or two to tweak a few things and change the code from a random starting deck to an "infinite" one.

Feel free to read further or look at my simulation:

Links

Matt Parker's video

My infinite game

Brayden Casella's paper

Richard Mann's web page about Beggar-thy-neighbour records