(* Vaclav Kotesovec 2011, based on article by R. Tauraso, 2006 *) << Combinatorica` (* semi=2 Rook + Leaper[d,d] *) (* semi=1 Rook + semi-Leaper[d,d] *) (* version for d=2 *) semi = 2; d = 2; Table[If[n == 1, 1, suma = 0; n1 = 0; Do[If[Mod[i - 1, d] == 0, n1 = n1 + 1], {i, 1, n}]; n2 = 0; Do[If[Mod[i - 2, d] == 0, n2 = n2 + 1], {i, 1, n}]; Do[Do[Do[ Do[part1 = (-1)^(r1 + r2)* semi^(c1 + c2)*(n - (r1 + r2) - (c1 + c2))!* Binomial[n1 - r1, c1]*Binomial[n2 - r2, c2]; If[c1 == 0, If[r1 == 0, nl1 = 1, nl1 = 0];, nl1 = NumberOfCompositions[r1 - c1, c1];]; If[c2 == 0, If[r2 == 0, nl2 = 1, nl2 = 0];, nl2 = NumberOfCompositions[r2 - c2, c2];]; Do[Do[ If[c1 == 0, z1 = {};, z1 = Compositions[r1 - c1, c1][[l1]];]; If[c2 == 0, z2 = {};, z2 = Compositions[r2 - c2, c2][[l2]];]; z = Flatten[{z1, z2}]; Do[m = NthSubset[p, Range[c1 + c2]]; u = Length[m]; If[u == 0, s = u, s = u + Sum[z[[m[[i]]]], {i, 1, u}];]; If[n1 - s >= 0 && n2 - (r1 + r2 - s) >= 0, suma = suma + part1*Binomial[n1 - s, u]*u!* Binomial[n2 - (r1 + r2 - s), c1 + c2 - u]*(c1 + c2 - u)!;]; , {p, 0, 2^(c1 + c2) - 1}]; , {l2, 1, nl2}]; , {l1, 1, nl1}]; , {c2, 0, Min[r2, n2 - r2]}]; , {c1, 0, Min[r1, n1 - r1]}]; , {r2, 0, n2 - 1}]; , {r1, 0, n1 - 1}]; suma] , {n, 1, 18}]