This is another prolog task that I can’t solve at this moment. I have to write a predicat p(X,Y), where X is list of lists of number and Y is a list of numbers. The predicat has to verify:
1) if X can be presented as a concatenation between 2 elements from Y.
2) X has a odd number of elements.
3) Sum of all elements in X is last element in Y.
Maybe as a separate tasks 2, 3 could be written easy. Problem is at 1)
Thank you in advance. I feel sorry for posting such an easy tasks, but prolog really drives me crazy. I have read all my lections over and over again. But the situation is similar to this:
school: 3+x=5, x = ?
exam: cos(x+y+z) + lim (5x+y)/t = …. If you know what I mean. Thank you once again!
Checking for concatenations is done with
append/3, which is more commonly used to build them but like many Prolog predicates works “in the opposite direction” as well. More specifically,append(A,B,C)checks whetherCis the concatenation ofAandB. So,checks whether there is a element
AinYand a elementBinYsuch that their concatenation unifies withX.(Note that this does not check whether
AandBare distinct elements ofY.)