Answered step by step
Verified Expert Solution
Question
1 Approved Answer
[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]
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started