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

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -