You're reading: cp's mathem-o-blog

The Double Back puzzle is a nice mix of Towers of Hanoi and Solitaire

This post is both a video and text. The content is largely the same in both versions, so you can pick one to look at.

I’d like to show you a puzzle, or game for one person, that Ed Kirkby came up with. Ed showed this to me at the Big MathsJam gathering last year.

I was walking around MathsJam and people were doing all sorts of stuff and Ed was quietly sat at a table with some cards in front of them, and a couple of people were gathered around with thoughtful faces, so I thought “oh that looks interesting” and I walked over and Ed explained the rules of this game to me.

And like most things at MathsJam, I didn’t immediately know the solution but it really got to me, so I went away and tried to find a solution myself. It was really fun and it was one of those pure experiences of mathematical discovery that you really remember.

I kept grabbing other people and saying, “have you seen Ed’s puzzle? Come over here. Ed, explain this puzzle to this person!” I did that for the duration of the weekend, and for a little while after I got back home.

I’ll show you what the puzzle is.

Take two sets of cards numbered 1 to 4, and lay them out in two rows. The game is to get them the other way round, so each row goes 4, 3, 2, 1.

The things you are allowed to do are to swap two cards that are adjacent numbers and in adjacent columns.

So you can swap the four and three here:

You can also swap to the other row.

You can’t swap the four and the two here because they’re not adjacent numbers.

It’s a permutations puzzle. And with a bit of thinking, a lot of just making random moves, eventually I worked out how to do it for four cards (or two lots of four cards, to be precise).

It took me a few more goes to be sure that I’d found the shortest solution — the fewest moves — but then five really stumped me.

When I tried six cards, I wasn’t sure it was possible at all: there was a point where I kept getting stuck.

So I was really unsure, and Ed was unsure as well – they didn’t know if there was a solution for every number of cards. They’d written some code that very slowly churned out solutions for small $n$, but didn’t have a general solution.

So I did my usual problem solving technique which was, if I couldn’t do it with four cards, do it with three cards, and very briefly with two cards. Then after a while I sort of started seeing a pattern.

I came away from Big MathsJam not knowing how to solve this puzzle.

I kept playing with it when I should have been working, and eventually I think I’ve sort of got the vibe of how it works and I’m pretty sure now I can solve it for any number of cards. I haven’t written down a really rigorous algorithm for doing it but I’ve got a general idea.

Interactive version

Something that often happened when I was playing with cards was that I’d forget which way I was going, because when you don’t have a strategy you’re sort of making lots of moves to see where they’ll go, and then maybe you want to backtrack a bit, and you go like wait wait — which end did the aces start at? You’re continually picking up cards and moving them, and if you’re as clumsy as I am they scatter all over the place and you end up unsure if you’re in a valid state.

So it won’t surprise you to learn that I made an online version of this.

Big MathsJam happens in November, and by the time I’d got this online version working it was getting close to Christmas and I thought, “we need something that’s not playing cards to be the pieces – why shouldn’t it be baubles? They’re circles, they’re easy to draw.”

So I spent some time drawing a bauble image and making it look Christmassy. I didn’t quite get it ready for last Christmas, so I spent some more time improving the interface and I made it fully keyboard accessible.

And then I made a note to write a post about it in December 2023. And here we are!

I think this is a nice Christmas puzzle: I think the set-up and the rules are easy to remember, and it only needs a pack of cards, which you’ll probably have lying around.

So over Christmas, if there’s a quiet moment, if you get some playing cards in your Christmas cracker or just some pieces that you can put in an easy to identify order, try showing this to someone.

So there you go, that’s the Double Back puzzle, invented by Ed Kirkby, online version made by me.

(will not be published)

$\LaTeX$: You can use LaTeX in your comments. e.g. $ e^{\pi i} $ for inline maths; \[ e^{\pi i} \] for display-mode (on its own line) maths.

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>