- 18,384,171,550,626,816 / 3,359,232 = 5,472,730,538

1. Let's say that we're trying to count the number of essentially-invariant grids for some grid transformation, g.

2. Without loss of generality, we can assume that digits 1-9 are laid out in order on the top row of an essentially-invariant grid. Since digit labels are irrelevant, we won't multiply by 9! at the end.

3. We make 9 lists, one per digit, showing the positions that the digit could occupy on the grid, given its known position in the top row. That's 5184 "templates" per digit.

4. For each template, work out what happens to it when successive powers of g are applied. If the template is called x, then you want the set of each possible (g^i)x to consist of non-overlapping templates: if not, delete the template from the list; but if so, replace the template by the union of all (g^i)x. You could call these replacements "extended templates".

5. Now run a 9-deep loop (or maybe 8-deep is good enough) looking for 9 non-overlapping extended templates, one from each of the per-digit lists. Or, nearly do that: when at level d in the loop, if you find that one of the extended templates from a higher level has occupied digit d's cell in the top row, then you contribute the empty template instead of one from your list.

And that's all there is to it. I'd rather not tell you just how long it took to debug this stuff though

btw, I was wrong about class 22: it has 9! x 323928 invariants. The two classes needed to finish off the calculation were class 32 (9! x 6342480) and class 134 (9! x 449445888).