%%%%%% GRAFO A TRIFOGLIO (shamrock)   %%%%%%%
%%%% Usa con N = 3*K con K >= 3
%%%% trifa ha HC
%%%% trifb non ha HC 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Ci sono 3 loops con nodi
%%%% 1,4,7,10,...
%%%% 2,5,8,11,...
%%%% 3,6,9,12,...
%%%% E i collegamenti tra loops con i 3 archi
%%%% aggiunti in trifa e trifb
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

trifa(N,[[1,5],[2,6],[3,4] | R]) :-
   N > 3,
   triangoli(N,R).

trifb(N,[[1,5],[2,6],[3,1] | R]) :-
   N > 3,
   triangoli(N,R).

triangoli(N,R) :-
   tri(1,N,R1),
   tri(2,N,R2),
   tri(3,N,R3),
   append([[N2,1]|R1],[[N1,2]|R2],R4),
   N1 is N - 1,
   N2 is N - 2,
   append(R4,[[N,3] |R3],R).

tri(M,N,[]) :-
    M > N - 3,
    !.
tri(M,N,[[M,M3]|R]) :-
   M3 is M + 3,
   tri(M3,N,R).
   
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
