prolog - Check If Everything In Head Is Less Than Tail -
given list containing sublists [[1].[2],[3]] how check see if head of first sublist in list less rest of heads of other sublists?
comparison of standard order of terms in iso-prolog can applied - recursively - arbitrary complex structures.
then problem solved like
first_head_is_less([h|r]) :- maplist(@<(h), r).
test:
?- first_head_is_less([[1],[2],[3]]). true. ?- first_head_is_less([[10],[2],[3]]). false.
edit code above must refined, because fail (for instance) on this:
?- first_head_is_less([[1,2],[1,3],[3]]). true.
which incorrect. here stricter test:
first_head_is_less([h|r]) :- maplist(head_is_less(h), r). head_is_less([f|_], [e|_]) :- f @< e.
Comments
Post a Comment