cross(Goal, Planks, Solution) :- layplanks(Goal, Planks, 0, Solution).

layplanks(Goal,_,Current,[]) :- Current >= Goal.
layplanks(Distance, Planks, Current, [Plank|MorePlanks]) :-
    select(Plank, Planks, Remaining),
    NewEnd is Current + Plank, \+over_pit(NewEnd),
    layplanks(Distance, Remaining, NewEnd, MorePlanks).

over_pit(N) :- pit(Start,Width), End is Start + Width, N >= Start, N < End.

pit(5,7).
pit(15,3).

% Jon Stephens, s15 final exam
notInPit([],_).
notInPit([p(B,E)|T],Pos) :- notInPit(T,Pos), \+between(B,E,Pos).

myselect(X, [X|T], T).
myselect(X, [H|T], [H|N]) :- myselect(X, T, N).
