|
Self-test 9 Solutions
|
| Multiple solutions in list processing | ||
|
/* ************************************************ */
/* */
/* delete_one/3 */
/* Arg 1: */
/* Arg 2: List */
/* Arg 3: List */
/* Summary: true if Arg 3 is Arg 2 with an */
/* instance of Arg 1 deleted. */
/* Author: P J Hancox */
/* Date: 28 October 1994 */
/* */
/* ************************************************ */
% 1 terminating condition
delete_one(Elem, [Elem|Tail], Tail).
% 2 recursive
delete_one(Elem, [Head|Tail1], [Head|Tail2]) :-
\+ (Elem = Head),
delete_one(Elem, Tail1, Tail2).
This requires the addition of one test. Note that this solution doesn't have recourse to extra-logical extensions of Prolog, such as the cut. |
||