Question: Need in prolog code for both parts 1. Define a procedure (predicate) sumTheList(X,Y) which takes a list X of numbers and stores their sum in
Need in prolog code for both parts
1. Define a procedure (predicate) sumTheList(X,Y) which takes a list X of numbers and stores their sum in Y.
?- sumTheList ([0,1,2,3],Y). Y = 6
This can be done with one fact and one rule. You will need to recursively define the function with an appropriate base case and recursive call.
2. Define a procedure (predicate) listSquare(X,Y) which takes a list X of numbers and stores their squares in a list Y
?- listSquare ([0,1,2,3],Y). It will respond with Y = [0,1,4,9]. This can be done with one fact and one rule. You will need to recursively define the function with an appropriate base case and recursive call.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
