%% Note the execution order of the clauses. %% We should not call hexrewrite with two %% uninstantiated arguments! %% polyhexnhexes(X,N) :- %% M is N-1, %% nzeros(L,M), %% it2hexrewrite(X,[1,1,1,1,1,1],L). %% %% it2hexrewrite([1,1,1,1,1,1],[1,1,1,1,1,1],[]) :- %% !. %% %% it2hexrewrite(X,Y,[0|L]) :- %% it2hexrewrite(Z,Y,L), %% hexrewrite(X,Z). polyhexnhexes(X,N) :- it2hexrewrite(X,[1,1,1,1,1,1],N). %% By the size (number of hexes). %% it2hexrewrite(X,Y,N) matches when X can be rewritten %% to Y with N-1 rewrites: it2hexrewrite([1,1,1,1,1,1],[1,1,1,1,1,1],1) :- !. it2hexrewrite(X,Y,N) :- M is N-1, it2hexrewrite(Z,Y,M), hexrewrite(X,Z).