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

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

L=Expand[Cyclotomic[2,x^(9)]Cyclotomic[3,x^(4)]];

n=36;

B=Array[0&,Length[L]];
For[j=2, j≤Length[L], B[[j]]=Mod[L[[j,2]],n];
j++];
B⋃{}

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

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

n=36;

(*B=Array[0&,10];

For[i=1, i≤Length[B],
B[[i]]=RandomInteger[n-1];
i++];
B⋃{}*)

B={0,4,8,9,13,17}

Length[B];

Tile=Array[0&,1000000];
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]]⋃{};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⋃{},1];
Length[Tile]
Tile

 (* So we have tiles mod 36. Instead of shifting the elements, i run the fill-out procedure for n=144 and the shifted B below. It gives the same.*)

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

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

n=144;


B={0,4,8,9,13,17};
B=B⋃(B+36)⋃(B+72)⋃(B+108)

Length[B];

Tile=Array[0&,1000000];
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]]⋃{};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⋃{},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⋃{},1];
Length[Tile]
Tile

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

(*Here comes an old and badly programmed version of the Fourier-selection. But it is correct, just annoyingly many notations and sets appearing.*)

Dynamic[{j,v,vvv,vvvv}]

T2=Tile;

Clear[H];

Length[T2]

H=Array[0&,{Length[T2],144}];
MF=Array[0&,Length[T2]];
MT=Array[0&,Length[T2]];
For[j=1, j≤Length[T2], 
For[k=1, k≤144,
If[MemberQ[T2[[j]],Mod[k,144]],H[[j,k]]=1];
k++];
j++];

v=1;
For[j=2, j≤Length[T2],
For[k=1, k≤144,
If[(Not[Chop[Fourier[H[[1]]]][[k]]==Chop[Fourier[H[[j]]]][[k]]])∧(Chop[Fourier[H[[1]]]][[k]]==0∨Chop[Fourier[H[[j]]]][[k]]==0), MF[[v]]=H[[j]];MT[[v]]=T2[[j]]; v=v+1; k=145];
k++];
j++]; 


MT=Drop[MT⋃{},1];
MF=Drop[MF⋃{},1];
Length[MF]

MMF=Array[0&,Length[T2]];
MMT=Array[0&,Length[T2]];
vvv=1;

For[j=2, j≤Length[MF],
For[k=1, k≤144,
If[(Not[Chop[Fourier[MF[[1]]]][[k]]==Chop[Fourier[MF[[j]]]][[k]]])∧(Chop[Fourier[MF[[1]]]][[k]]==0∨Chop[Fourier[MF[[j]]]][[k]]==0), MMF[[vvv]]=MF[[j]];MMT[[vvv]]=MT[[j]]; vvv=vvv+1; k=145];
k++];
j++]; 

MMT=Drop[MMT⋃{},1];
MMF=Drop[MMF⋃{},1];
Length[MMF]

MMMF=Array[0&,Length[T2]];
MMMT=Array[0&,Length[T2]];
vvvv=1;

For[j=2, j≤Length[MMF],
For[k=1, k≤144,
If[(Not[Chop[Fourier[MMF[[1]]]][[k]]==Chop[Fourier[MMF[[j]]]][[k]]])∧(Chop[Fourier[MMF[[1]]]][[k]]==0∨Chop[Fourier[MMF[[j]]]][[k]]==0), MMMF[[vvvv]]=MMF[[j]];MMMT[[vvvv]]=MMT[[j]]; vvvv=vvvv+1; k=145];
k++];
j++]; 

MMMT=Drop[MMMT⋃{},1];
MMMF=Drop[MMMF⋃{},1];
Length[MMMF]

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

M4F=Array[0&,Length[T2]];
M4T=Array[0&,Length[T2]];
v4=1;

For[j=2, j≤Length[MMMF],
For[k=1, k≤144,
If[(Not[Chop[Fourier[MMMF[[1]]]][[k]]==Chop[Fourier[MMMF[[j]]]][[k]]])∧(Chop[Fourier[MMMF[[1]]]][[k]]==0∨Chop[Fourier[MMMF[[j]]]][[k]]==0), M4F[[v4]]=MMMF[[j]];M4T[[v4]]=MMMT[[j]]; v4=v4+1; k=145];
k++];
j++]; 

M4T=Drop[M4T⋃{},1];
M4F=Drop[M4F⋃{},1];
Length[M4F]

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

Dynamic[{j,v5}]
M5F=Array[0&,Length[T2]];
M5T=Array[0&,Length[T2]];
v5=1;

For[j=2, j≤Length[M4F],
For[k=1, k≤144,
If[(Not[Chop[Fourier[M4F[[1]]]][[k]]==Chop[Fourier[M4F[[j]]]][[k]]])∧(Chop[Fourier[M4F[[1]]]][[k]]==0∨Chop[Fourier[M4F[[j]]]][[k]]==0), M5F[[v5]]=M4F[[j]];M5T[[v5]]=M4T[[j]]; v5=v5+1; k=145];
k++];
j++]; 

M5T=Drop[M5T⋃{},1];
M5F=Drop[M5F⋃{},1];
Length[M5F]

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

F1=Array[1&,144];
F2=Array[1&,144];
F3=Array[1&,144];
F4=Array[1&,144];
F5=Array[1&,144];


J={T2[[1]],MT[[1]],MMT[[1]],MMMT[[1]],M4T[[1]]}
For[j=1,j≤144,
If[Chop[Fourier[H[[1]]]][[j]]==0, F1[[j]]=0];
j++];
For[j=1,j≤144,
If[Chop[Fourier[MF[[1]]]][[j]]==0, F2[[j]]=0];
j++];
For[j=1,j≤144,
If[Chop[Fourier[MMF[[1]]]][[j]]==0, F3[[j]]=0];
j++];
For[j=1,j≤144,
If[Chop[Fourier[MMMF[[1]]]][[j]]==0, F4[[j]]=0];
j++];
For[j=1,j≤144,
If[Chop[Fourier[M4F[[1]]]][[j]]==0, F5[[j]]=0];
j++];

F1;
F2;
F3;
F4;
F5;
(*{{2,3,8,16},{4,9}};*)

FF1=Array[0&,144];
FF2=Array[0&,144];
FF3=Array[0&,144];
FF4=Array[0&,144];
FF5=Array[0&,144];

For[j=1,j≤144,
If[F1[[j]]==0, FF1[[j]]=j];
j++];
For[j=1,j≤144,
If[F2[[j]]==0, FF2[[j]]=j];
j++];
For[j=1,j≤144,
If[F3[[j]]==0, FF3[[j]]=j];
j++];
For[j=1,j≤144,
If[F4[[j]]==0, FF4[[j]]=j];
j++];
For[j=1,j≤144,
If[F5[[j]]==0, FF5[[j]]=j];
j++];

FF1=Drop[FF1⋃{},1]-1;
FF2=Drop[FF2⋃{},1]-1;
FF3=Drop[FF3⋃{},1]-1;
FF4=Drop[FF4⋃{},1]-1;
FF5=Drop[FF5⋃{},1]-1;

FF={FF1,FF2,FF3,FF4,FF5};

For[m=1,m≤5,
For[j=1,j≤Length[FF[[m]]],
FF[[m,j]]=GCD[FF[[m,j]],144];
j++];
m++];
For[j=1,j≤5,
FF[[j]]=FF[[j]]⋃{};
j++];
FF;
FT=144/FF
CFT=Array[0&,Length[FT]];
For[j=1,j≤Length[FT],
CFT[[j]]=Complement[Divisors[144],FT[[j]]];
j++];
CFT