%%   知識情報処理実習 r5の練習問題 解答例

% 1.

are_edges(a,[b,c]).
are_edges(b,[a,c,d]).
are_edges(c,[d]).
are_edges(d,[]).

list_length([],0).
list_length([_|Y],N) :- list_length(Y,N1), N is N1+1.

n_of_edges(N,K) :-
    are_edges(N,L), list_length(L,K).

test5_1(K) :- n_of_edges(a,K).

% 2.

mymem(X,[X|_]).
mymem(X,[_|Xs]) :- mymem(X,Xs).

has_duplication([A|L]) :- mymem(A,L).
has_duplication([_|L]) :- has_duplication(L).

test5_2_1 :- has_duplication([a,b,a]).
test5_2_2 :- has_duplication([a,b]).