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


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

n=72;

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

B=Array[0&,Length[L]];
For[j=2, j≤Length[L], B[[j]]=Mod[L[[j,2]],n];
j++];
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;


KK=Tile;

Tilea=Array[0&,1000000];
h=1;
For[p=1,p≤Length[KK],
For[k=0,k≤1,
For[j=0, j≤1,
For[m=0,m≤1,
For[m2=0,m2≤1,
For[m3=0,m3≤1,
For[m4=0,m4≤1,
For[m5=0,m5≤1,
For[m6=0,m6≤1,
For[m7=0,m7≤1,
For[m8=0,m8≤1,
For[m9=0,m9≤1,
Tilea[[h]]={0,72k+KK[[p,2]],72j+KK[[p,3]],72m+KK[[p,4]],72m2+KK[[p,5]],72m3+KK[[p,6]], 72m4+KK[[p,7]],72m5+KK[[p,8]],  72m6+KK[[p,9]],72m7+KK[[p,10]], 72m8+KK[[p,11]], 72m9+KK[[p,12]]}⋃{};h=h+1;
m9++];
m8++];
m7++];
m6++];
m5++];
m4++];
m3++];
m2++];
m++];
j++];
k++];
p++];

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

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

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

T2=Tilea;

Clear[H];

Length[T2]

H=Array[0&,{Length[T2],144}];
MF=Array[0&,100];
MT=Array[0&,100];

For[j=1, j≤Length[T2], 
For[k=1, k≤144,
If[MemberQ[T2[[j]],Mod[k,144]],H[[j,k]]=1];
k++];
j++];

MF[[1]]=H[[1]];
MT[[1]]=T2[[1]];

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


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


MT

(* This part below is just checking that MT and MF are really what they should be*)

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

T2={{0,1,4,5,48,49,52,53,96,97,100,101},{0,3,12,15,48,51,60,63,96,99,108,111},{0,1,4,21,48,49,52,69,96,97,100,117},{0,1,12,13,48,49,60,61,96,97,108,109},
{0,1,4,7,13,24,28,37,43,48,49,52},
{0,1,4,21,24,25,28,45,48,49,52,69},{0,1,4,5,24,25,28,29,48,49,52,53},
{0,1,6,7,12,13,36,37,42,43,48,49},{0,1,12,13,24,25,36,37,48,49,60,61},
{0,3,6,9,12,15,36,39,42,45,48,51},{0,3,12,15,24,27,36,39,48,51,60,63}
};

Clear[H];

Length[T2]

H=Array[0&,{Length[T2],144}];
MF=Array[0&,100];
MT=Array[0&,100];

For[j=1, j≤Length[T2], 
For[k=1, k≤144,
If[MemberQ[T2[[j]],Mod[k,144]],H[[j,k]]=1];
k++];
j++];

MF[[1]]=H[[1]];
MT[[1]]=T2[[1]];

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


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



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


J=MF;
F1=Array[1&,{Length[J],144}];

For[i=1,i<=Length[J],
For[j=1,j≤144,
If[Chop[Fourier[J[[i]]]][[j]]==0, F1[[i,j]]=0];
j++];
i++];


F1;


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

FF1=Array[0&,{Length[F1],144}];

For[i=1,i≤Length[F1],
For[j=1,j≤144,
If[F1[[i,j]]==0, FF1[[i,j]]=j];
j++];
i++];

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

FF=FF1-1;

For[m=1,m≤Length[FF1],
For[j=1,j≤Length[FF1[[m]]],
FF[[m,j]]=GCD[FF[[m,j]],144];
j++];
m++];
FF;
For[j=1,j≤Length[FF],
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

(* And from FT and CFT we see that one of the tiles is always periodic*)