(* {{2,3,4,8,16},{9}}} *)

Dynamic[{j,i,g, mark}]
Clear[n,B,R,Tile,A,U,mark,T,g,x];

L=Expand[Cyclotomic[3,x]];

n=9;

B={0,1,2};

(* The only possible complement of B mod 9 is {0,3,6} *)

Tile=Array[0&,100000];
h=1;
For[k=0,k<=15,
For[j=0, j≤15,
Tile[[h]]={0,9k+3,9j+6}⋃{};h=h+1;
j++];
k++];

Tile=Drop[Tile⋃{0},1];

n=144;
For[j=1, j≤Length[Tile], P=Tile[[j]];
For[i=2, i<=Length[P], 
If[MemberQ[Tile,Mod[P-P[[i]],n]⋃{}], Tile[[j]]=0;i=Length[P]+1];
i++];
j++]; 
Tile=Drop[Tile⋃{},1];
Length[Tile]
Tile


(* {{2,3,4,8,16},{9}}} *)


Dynamic[{jj,j,i,g, mark, rr}]
Clear[n,J,B,R,Tile,A,U,mark,T,g,x];

n=144;

J={{0,51,102},{0,57,96},{0,57,105},{0,57,114},{0,60,93},{0,60,102},{0,60,111},{0,60,120},{0,66,87},{0,66,96},{0,66,105},{0,66,114},{0,66,123},{0,66,132},{0,69,84},{0,69,93},{0,69,102},{0,69,111},{0,69,120},{0,69,129},{0,69,138},{0,75,78},{0,75,87},{0,75,96},{0,75,105},{0,75,114},{0,75,123},{0,75,132},{0,75,141},{0,78,84},{0,78,93},{0,78,102},{0,78,111},{0,78,120},{0,78,129},{0,78,138},{0,84,87},{0,84,96},{0,84,105},{0,84,114},{0,84,123},{0,84,132},{0,84,141},{0,87,93},{0,87,102},{0,87,111},{0,87,120},{0,87,129},{0,87,138},{0,93,96},{0,93,105},{0,93,114},{0,93,123},{0,93,132},{0,93,141},{0,96,102},{0,96,111},{0,96,120},{0,96,129},{0,96,138},{0,102,105},{0,102,114},{0,102,123},{0,102,132},{0,102,141},{0,105,111},{0,105,120},{0,105,129},{0,105,138},{0,111,114},{0,111,123},{0,111,132},{0,111,141},{0,114,120},{0,114,129},{0,114,138},{0,120,123},{0,120,132},{0,120,141},{0,123,129},{0,123,138},{0,129,132},{0,129,141},{0,132,138},{0,138,141}};

rr=1;
gcd=Array[0&,{Length[J],Length[J[[1]]]}];
For[kk=1,kk≤Length[J],
For[mm=2,mm≤Length[J[[kk]]],
gcd[[kk,mm]]=GCD[gcd[[kk,mm-1]],J[[kk,mm]]];
mm++];
kk++];
For[kk=1,kk≤Length[J], gcd[[kk,Length[J[[1]]]]]=GCD[gcd[[kk,Length[J[[1]]]]],n];
kk++];

maxperiod=Array[0&,{Length[J],10000}];

For[jj=1, jj≤Length[J],Clear[B,R,Tile,A,U,mark,T,g,x];n=144;n=n/gcd[[jj, Length[J[[1]]]]];B=J[[jj]]/gcd[[jj,Length[J[[1]]]]];

Tile=Array[0&,100000];
R=Array[0&,n];
A=Array[200&,{n/Length[B],n,Length[B]}];
U=Array[0&,n/Length[B]];
U[[1]]=B;
mark=Array[1&,n/Length[B]+1];
T=Array[{0}&,n/Length[B]];
g=1;

For[i=1, i>0,
If[Length[U[[i]]]==n,  Tile[[g]]=T[[i]]⋃{};maxperiod[[jj,g]]=99;
For[ff=Length[Divisors[n]]-1, ff>0,
If[Mod[((Divisors[n][[ff]])+Tile[[g]]),n]⋃{}==Tile[[g]],Tile[[g]]=0;maxperiod[[jj,g]]=Divisors[n][[ff]];ff=0;
 ];
ff=ff-1];
 g=g+1;T[[i]]=T[[i-1]];mark[[i]]=1;A[[i]]=Array[200&,{n,Length[B]}];i=i-1,
For[j=1, j≤n,k=100;
If[Not[MemberQ[U[[i]],Mod[j,n]]], k=0;
For[m=1, m≤Length[B],
If[U[[i]]⋂ Mod[(j-B[[m]])+B,n]=={}, k=k+1; A[[i,j,m]]=Mod[j-B[[m]],n]];
m++]];
R[[j]]=k;
j++];
min=Min[R]; 
If[(Not[min==0]),
t=Catch[Do[If[R[[ii]]==min, Throw[ii]],{ii,n}]];
If[mark[[i]]≤Length[B],
For[b=mark[[i]], b<=Length[B],mark[[i]]=b+1;z=0;
If[Not[A[[i,t,b]]==200], U[[i+1]]=U[[i]]⋃Mod[A[[i,t,b]]+B,n]; T[[i+1]]=T[[i]]⋃{A[[i,t,b]]}; b=Length[B]+1;z=1;i=i+1;];
b++];
If[z==0, mark[[i]]=1;A[[i]]=Array[200&,{n,Length[B]}];i=i-1];
, mark[[i]]=1;A[[i]]=Array[200&,{n,Length[B]}];T[[i]]=T[[i-1]];i=i-1];
, mark[[i]]=1;A[[i]]=Array[200&,{n,Length[B]}];T[[i]]=T[[i-1]];i=i-1];
];
];

Tile=Drop[Tile⋃{0},1];
Length[Tile]
Tile;

For[j=1, j≤Length[Tile], P=Tile[[j]];
For[i=2, i<=Length[P], 
If[MemberQ[Tile,Mod[P-P[[i]],n]⋃{}], Tile[[j]]=0;i=Length[P]+1];
i++];
j++]; 
Tile=Drop[Tile⋃{0},1];
If[Not[Length[Tile]==0], rr=rr+1];
Tile;
jj++];
rr

For[j=1,j≤Length[maxperiod],maxperiod[[j]]=Drop[maxperiod[[j]]⋃{0},1];
j++];
maxperiod