A notebook page where the formula S = (T − C) / 2 = 27 is crossed out and replaced by S = (T − C) − loops = 54 − 22 = 32, with Swudoku tiles taped beside it in a loop of three and a pair.

The mathematics of the perfect Swudoku game

The story of Swudoku is definitely one of evolution. Apart from the core idea of descrambling a sudoku board, changes to the mechanics, the colours, and the scoring have made today's game quite different to the one we started with. Along the way, particularly as scoring stabilised, the idea of a "perfect game” presented itself. In other words, what's the fewest number of swaps a board can be solved in? Anyone playing a game would probably want to know this so they have something to measure themselves against. My first attempt at answer was simple:

S = (T − C) / 2

S is the best possible swap score, T is the total number of tiles, and C is the number of tiles that start in the correct place. (The answer is rounded up, because there's no such thing as half a swap.)

New to Swudoku? The guide to swap sudoku and the how to play page cover the basics.

Let's look at an example:

Game #500. 81 total tiles with 27 starting in the correct position.

S = (81 − 27) / 2

S = 27

The idea being that if every swap I made was a Double Swap, then all 54 incorrectly placed tiles would be in their correct positions in 27 swaps.

This idea held for a while. But something bugged me…

There is no way a board would have 100% Double Swaps. I mean maybe it's possible, but statistically improbable. On most boards, my "27" was a mark that no player could ever hit! And for those of us that want to really know how good we are, measuring ourselves against impossibility just ain't fair!

Back to the drawing board!

After a little meandering, I figured it out. But to help you understand, let's wrap this mathematics in a story.

A dinner party in the wrong seats.

It's Saturday night and your turn to host dinner amongst the friend group. Places are set, food is just about ready, guests take their seats… but wait! They don't take their seats, they take random seats. Not cool, guests! Did you not see the placecards? Never mind, let's get everyone into their correct seats. But dinner is about to be served, so we want to make this swapping as efficient as possible… and for the sake of the analogy, there is a rule that you may only ask guests to swap directly with another guest.

Mia is in Jack's seat and Jack is in Mia's, so one swap seats them both: a Double Swap. Nice! Sam, Ava, and Leo are trickier. Sam is in Ava's seat, Ava is in Leo's, and Leo is in Sam's. No two of them are in each other's chairs, so the first swap can seat only one person. That leaves a pair, and one more swap finishes it. A loop of 3 takes 2 swaps.

Diagram of a loop of three misplaced tiles that takes 2 swaps, beside a pair that takes 1 swap.

The same goes for any loop. A loop of k people always takes k − 1 swaps, because only the last swap seats two people at once. Sam, Ava, and Leo: 3 people − 1 = 2 swaps.

So the fewest swaps is the number of people in the wrong seats minus the most loops you can make.

On the board, the tiles are the guests, the cells are the seats, and the solved sudoku is the seating plan. Once we saw the loops, the whole thing cracked open. (Apparaently these are called permutation cycles.)

So, let's look at our game #500 again. Because I know the completed board (a privilege of being the game designer), I can see the 54 misplaced tiles split into 14 loops of 2, 6 loops of 3, and 2 loops of 4. That's 22 loops, and 54 − 22 = 32. Perfect on #500 is 32, not 27. My original formula was optimistic by 5 swaps! Sorry to everyone measuring themselves against that impossible standard!

The twist: repeated digits.

A Swudoku has nine of each digit, so a misplaced 7 can go in any cell waiting for a 7. That means the same tiles can often be grouped into loops in more than one way, and the groupings don't all cost the same. Merge two short loops into one long one and you lose a loop, which costs a swap.

So a script was written that takes each puzzle's starting board and its solution, and searches for the grouping with the most loops. That count sets the perfect score.

The same nine tiles grouped into three short loops costing 6 swaps, or into a longer loop costing 7 swaps.

Same tiles, different loops. The long way round costs an extra swap.

Can a clever order of swaps beat it?

This had me stuck for a little while. Surely a clever order of swaps could sneak under that number?

Well no. If the optimal is determined from the start, any deviations, at best, simultaneously add a swap while creating a new loop amd therefore an extra swap.

What perfect is, and what it isn't.

So can you use this knowledge to tune your game strategy? Not completely. Perfect is the fewest swaps you'd need if you knew the solution from the first move, and nobody does. You're solving the board as you swap, so you never hold the seating plan and can't count the loops mid-game. Perfect is a fixed property of each puzzle and is designed to be a measuring stick, not a strategy you can play.

Playing well without the solution.

So what does an honest swap sudoku strategy look like? Solve first, swap second. Work out where a tile belongs before you move it. A tile turns yellow when it's in its correct cell, and green when its row, column, or box is complete. When you're sure two tiles belong in each other's cells, swap them: a confirmed Double never costs you. And don't guess. Undo moves the tiles back, but the swap still counts.

A Swudoku board mid-solve where sudoku logic shows two grey tiles belong in each other's cells, a Double you've confirmed.

When you've worked out that two tiles belong in each other's cells, that's a Double.

The Swudoku scoring bands.

Now that we know how to calculate Perfect, we have an anchor for the scoreboard. The target runs from perfect up to the number of tiles out of place. Here's #500, which you can find in the archive .

  • Perfect: 32 swaps. The fewest possible swaps.
  • GOAT: 33–36 swaps. Within 4 of perfect.
  • Sharp: 37–43 swaps. Up to halfway to the top of the target.
  • Clean: 44–54 swaps. Inside the target.
  • Over target: 55+ swaps. More swaps than tiles out of place.
Swudoku scoring bands for puzzle 500, from Perfect at 32 swaps to Over target at 55 or more.

Find your perfect number.

Every day's board has its own perfect, set by its loops. See how close you can get. Play today's Swudoku .

Frequently asked questions.

Is there a perfect score in Swudoku?

Yes. Each puzzle has a Perfect score: the fewest possible swaps to solve that board, calculatable if you know the solution from the start. E.g. on #500 it's 32.

How is the minimum number of swaps calculated?

The misplaced tiles form closed loops. A loop of k tiles costs k − 1 swaps, so the minimum is the number of misplaced tiles minus the number of loops, using the grouping with the most loops.

Ready for today’s board?

Play Swudoku →