:- use_module(library(lists)).

% Representation av sökrymdsgrafer

successor(a, b).
successor(a, f).
successor(a, c).
successor(b, d).
successor(b, e).
successor(e, h).

final_state(h).

% depth_first(+Start, -Solution)
% Start is the initial state and
% Solution is a path from the initial state to the final state.

depth_first(Start, Solution) :-
        depth_first(Start, [Start], Solution).

depth_first(State, _, [State]) :-
        final_state(State).
depth_first(State, History, [State|Solution]) :-
        successor(State, NewState),
        \+ member(NewState, History),
        depth_first(NewState,[NewState|History], Solution).
