Question: Write two clauses in Prolog that determines if there are exactly two values in a list such that they sum a value N. The output

Write two clauses in Prolog that determines if there are exactly two values in a list such that they sum a value N. The output should be a single true if there exists two values whose sum is N or a single false if there are not. If there are multiple values whose sum is N then your program should only print true once.

Sample

List [1, 3, 5, 7] with N equal to 10 should print true. 7 + 3 = 10.

List [1, 3, 5, 7] with N equal to 20 should print false. No two values sum is 20.

List [7, 1, 10, 3, 8, 2] with N equal to 9 should print true. 2 + 7 = 9 and 8 + 1 = 9 and 1 + 8 = 9 and 7 + 2 = 9.

Restrictions

You are restricted to the following.

Use of at most 2 clauses.

+

,

;

.

!

:-

is

Lists

Head and tail syntax for list types

Variables

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!