Consider a $ 3d $ Latin hypercube with network $ n $ steps in each dimension so it has $ n ^ 3 $ positions. Coordinates $ X, Y, Z in {1,2, … n } $. I want to find all the permutations of them where they add to $ S = 3 (n + 1) / $ 2.

The number of permutations is different from zero only when $ n $ is odd and corresponds to A002047 of the Sloane sequence library. I've forced my way to generate the permutations via `permutations`

and `Subsets`

and it works well, but I wanted to see if `FindInstance`

could do better. It is easier to define the problem.

Here's what I've

```
nn = 3;
ss = 3 (num + 1) / 2;
yvars = Table[y[i], {hostel}]; (* instantiate the y[] and z[] variables *)
zvars = table[z[i], {hostel}];
xvars = Table[x[i] = i, {i, nn}]; (* just set them to {1, ..., nn} *)
(* Force Z to be a permutation *)
between Z = 1 <= zvars <= nn;
unequalZ = unequal @@ zvars;
(* same for Y *)
between Y = 1 <= yvars <= nn;
unequalY = unequal @@ yvars;
(* force the sums to match S *)
sumeqns = xvars + yvars + zvars == Table[ss, {nn}]; (* sum correctly *)
rules = FindInstance[{betweenZ,unequalZ, betweenY, unequalY, sumeqns},
Join @@ {yvars, zvars},
Integers,
20]
Length @ rules
(* 2 *)
```

It works well except that it is *slow*. With $ n = $ 7 It takes 22 seconds on my machine to get a single swap. Using my brutal force approach, I can get all the 244 permutations for when $ n = $ 9 in about 3 seconds.

I was wondering if there were other ways to get the constraints to `FindInstance`

this might be more appropriate for the treatment in his bowels. Thoughts?