Question: [PROLOG] Write a predicate absDiff that calculates the absolute difference of the corresponding elements of two lists. The result is also a list. ?- absDiff

[PROLOG]

[PROLOG] Write a predicate absDiff that calculates the absolute difference of the

Write a predicate absDiff that calculates the absolute difference of the corresponding elements of two lists. The result is also a list. ?- absDiff ([1,3,5,6], [3,5,2,1], L) L= [ 2, 2, 3, 5]. This predicate must also work if the two input lists are not the same length. We ask you to create two versions of this predicate: a) Assume that the missing elements in the shorter list have the value of 0. The result will be of length equal to the longer list. ?- absDiffA ([1,3,5, 6, 2,5], [3,5,2,1],L) . L-[2,2,3,5,2, 5]. ?- absDiffA (1,3,5,6], [3,5,2,1,2,5], L) . L= [ 2, 2, 3, 5, 2, 5] . b) Ignore the extra values of the longer list. The result will be of length equal to the shorter list. ?- absDiffB ([1,3,5, 6,2,5], [3, 5,2,1],L) L= [ 2, 2, 3, 5]. ?- absDiffB (1,3,5,6], [3,5,2,1,2,5], L) . L= [ 2, 2, 3, 5]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!