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](https://s3.amazonaws.com/si.experts.images/answers/2024/09/66dd3ec6c775c_55866dd3ec637eee.jpg)
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
Get step-by-step solutions from verified subject matter experts
