% A board is done when there is one peg left
done(L) :- sumlist(L, S), S = 1.

% Entry point
solve(L) :- helper([], L, [], D), reverse(D, E), printSteps([L|E]).

% The actual solver
helper(A,B,C,D) :- append(A,B,L), done(L), C=D.
helper(A,[1,1,0|T],C,D) :- append(A, [0,0,1|T], L), helper([], L, [L|C], D).
helper(A,[0,1,1|T],C,D) :- append(A, [1,0,0|T], L), helper([], L, [L|C], D).
helper(A,[H|T],C,D) :- append(A, [H], L), helper(L, T, C, D).

% Print out a list (probably a library function to do this, but I'm lazy)
printSteps([]).
printSteps([H|T]) :-
    print(H),
    print('\n'),
    printSteps(T).
