%% exercise 1
edge(a,b).
edge(a,c).
edge(b,d).
edge(c,d).
edge(e,f).
edge(f,e).
target(d).
target(f).
reachable(a).
reachable(X) :- edge(Z,X), reachable(Z).
good(X) :- target(X), reachable(X).


%% exercise 3
bintree(leaf(X)) :-
	integer(X).
bintree(branch(Left,X,Right)) :-
	integer(X),
	bintree(Left),
	bintree(Right).

genbt(0,leaf(0)).
genbt(N,branch(Left,N,Left)) :-
	N1 is N - 1,
	genbt(N1,Left).

postorder_naive(leaf(X),[X]).
postorder_naive(branch(Left,X,Right),L) :-
	postorder_naive(Left,L1),
	postorder_naive(Right,L2),
	append(L1,L2,L3),
	append(L3,[X],L).



