Question: Prolog language Write a predicate which processes a list of numbers by adding up every second number. The predicate is to work as shown below.

Prolog language

Write a predicate which processes a list of numbers by adding up every second number. The predicate is to work as shown below. (Note that you are not asked to check the input to be a valid list of numbers but can simply assume that your predicate always receive list of numbers).

?- addSecond([1,3,5,4],S). S = 7. ?- addSecond([1,3,5],S). S = 3. ?- addSecond([1,3],S). S = 3. ?- addSecond([1],S). S = 0. ?- addSecond([1,3,5],3). true.

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!