|
No, `order/1` generates "too-short" solutions otherwise. If you redefine `order/1` to be a little smarter, like so: order([]) :- \+ follows(_, _).
order([X]) :- \+ follows(_, X).
order([X,Y|L]) :-
follows(Y, X), order([Y|L]).
Then this works without knowing the length a priori, but it's less efficient: ?- order(L), forall((is_behind(X, _); is_behind(_, X)), member(X, L)).
L = [prancer, cupid, rudolph, dasher, blitzen, vixen, comet, donder, dancer] .
Instead I'd discover the set of names (and therefore list length) using `setof/3`; this is similarly efficient to my original solution: ?- setof(X, Y^(is_behind(X, Y); is_behind(Y, X)), M), length(M, N), length(L, N), order(L).
M = [blitzen, comet, cupid, dancer, dasher, donder, prancer, rudolph, vixen],
N = 9,
L = [prancer, cupid, rudolph, dasher, blitzen, vixen, comet, donder, dancer] .
|